Using Serenity-Cucumber, I am trying to build a test suite so that I can reuse the step definitions (Given, When, Then, And..) through out multiple feature files.
For example:
Scenario: User Logs in
Given User is on the Login page
When User Logs in using 'userName' and 'password'
Then User on page containing: '/logedin/url/path'
The above test case logs in a user and I will need to use it for other Scenarios. For example, if I add a test case to update a password, the above Scenario will need to be performed before the update password scenario.
The test will need to perform the Login steps and then update password steps. From my limited knowledge, it seems like I will need to have this in the Background:
step. So before my update password scenario I will have the following:
Background: User Logs in
Given User is on the Login page
When User Logs in using 'userName' and 'password'
Then User on page containing: '/logedin/url/path'
Scenario: User Updates Password
Given User is on the Manage Account page
When User clicks Update Password
And User type 'existingPassowrd' and 'newPassword'
And User clicks Update Password
Then Password is displayed as 'newPassword'
This gives me an error cucumber.runtime.DuplicateStepDefinitionException
which I understand, but I keep reading that serenity-cucumber gives the the option to reuse steps, which again, I get and is a good idea.
So, How do I reuse scenarios or a scenarios' step definitions in other tests? I don't need a new method for them, I just need to call the existing method that I created in the previous scenario.
Is there a way to do this?
Can I do something like this? (or do i not even need to write out the background?)
@Steps
User user;
//This is the background in the feature file.
//Instead of creating methods, I would just reference the pre-existing ones from the other test case.
@Given("^User is on the Login page$")
@When("^User Logs in using '(.*)' and '(.*)'$")
@Then("^User on page containing: '(.*)'$")
//This is the Scenario in the feature file
@Given("^User is on the Manage Account page$")
public void user_is_on_the_manage_account_page(String expectedUrl) throws Exception {
user.is_on_page(expectedUrl);
}
@When("^User clicks Update Password$")
public void user_clicks_update_password() throws Exception {
user.click_update_password();
}
code continues
...
...
...