I have a feature file
Feature: Create Profile
Scenario: Create Profile
Given I want to create a profile
When I create a profile
Then I should be navigated to Home Page
Then sign out link should exist
So the above runs all ok and asserts that it's indeed back in the Home Page and the sign out link exists.
And now I have another feature file.
Feature: Go to my account page
Scenario: Go to my account page
Given I want to go to my account page
When I go to my account page
Then I should be navigated to the my account page
Before running "When I go to my account page"
step, the user should "Create Profile"
.
So what I did was I appended the
When I create a profile
Then I should be navigated to Home Page
Then sign out link should exist
before When I go to my account page
.
But I see that I have duplicated the same code that is in the "Create Profile" feature/scenario.
How do I run the entire "Create Profile" feature/scenario inside the "Go to my account page" scenario?
I am using cucumber-jvm with Selenium and JUnit.
Did you see the Background DSL-feature? It would work for your case but is probably not what you're literally asking about. In this case you can require user to create profile by:
Feature: Create Profile
Background:
Given I create a profile
And I should be navigated to Home Page
And sign out link should exist
Scenario: Create Profile
# do nothing because all actions are in background
Scenario: Go to my account page
When I go to my account page
Then I should be navigated to the my account page
But you have to merge the two your feature files into a single feature file.
Also take a look at @Before and @After cucumber annotations - so that you can run some code to initialize (or create) an account for your test if previous solution wouldn't work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With