0

I have two feature files in features folder

features
login.feature
dashboard.feature

#feature1

feature: testing a new page

scenario: I want to test login screen
Given User is in home page
Then clicked on login button

#feature2
@login
scenario: I want to test dashboard screen
Given user in dashboard page
Then clicked on login button

I maintained the code in 2 separate step_defs

stepdefs
test_homepage.py
test_loginpage.py

Can I reuse the step of feature #1 in feature #2

2 Answers2

1

Direct answer to your question is no, it is not possible to use steps from one feature in a different feature if the steps are implemented in different folders.

However there are different work arounds as mentioned by Rahul. In addition to those, you can also create a utils folder as in any other framework and you can add methods which will perform all the actions in the util folder and then call the method in both the steps. This will help in reducing the code duplication.

Arun Sasi
  • 316
  • 5
  • 15
0

You can do 1 of two things here

  1. Use conftest file to keep all your common functions that you want to reuse across the step definitions.

2.Call the method into other step definitions by importing the class/method.