aleya
aleya

Reputation: 1

cucumber BDD selenium Java

how to reuse a step definition from one class to multiple feature class? eg. login.feature Scenario: it checks the login flow Given: User logs in the home page When: Then:

again another feature class logout.feature Scenario: it checks the logout flow Given: User logs in the home page When: Then: User logs out from home page We have step definition classes login want to use the Given step of login.java in logout.feature without rewriting it in logout.java.

Upvotes: 0

Views: 245

Answers (1)

Mohit Tater
Mohit Tater

Reputation: 453

If you want to use the step in the logout.feature file, just write the step "Given: User logs in the home page" in the logout.feature file. Cucumber will automatically link the step to the login.java file.

If you want to access the step in the logout.java file then call the function which is mapped to the required step.

@And("^I login in the home page$")
public void I_login_in_the_home_page(){
//login logic
}

For above eg you can call I_login_in_the_home_page() from logout.java file.

Upvotes: 1

Related Questions