Reputation: 5494
We are building our automated end-to-end tests following the page object model approach using WebdriverIO and Cucumber.js. We have a number of features that have the same step expressions, like "Then I should see a 'Continue' button displayed". Each feature corresponds to a different page object so the implementation would be different.
Is there a way to scope a step definition function to a specific feature and/or scenario?
The work-around for this is ugly and means we have to add a bunch of superfluous words to the step expression to make each one globally unique.
We are using:
Upvotes: 1
Views: 1234
Reputation: 3067
Cucumber is meant to be a communication tool, not an implementation tool, and thus doesn't allow for ambiguous step definitions in this way
You ideally want a terse library of steps that cover scenarios in more generalised language so that you can drill down into the problems further down.
You should be aiming to describe Givens as prerequisites, Whens as user actions through the journey and Thens as what the user should expect to encounter as your journey completes, such as:
Given Jane logs into her account
When she completes the example form
Then she should see an example form confirmation page with the following information:
| status | closed |
| description | an example |
| name | Jane |
Which is something that is easily read by the business peoples, and clearly defines the intent of the test that you have written.
"I should see a continue button" seems like something that would be present in an integration test, rather than an end to end test, and would be better suited to a test in something akin to Mocha
If you wish to keep your language (however much I believe it shouldn't be within the Gherkin level), I'd recommend going through the text of the element and finding any button with the corresponding text that the step has provided, as it should be the only one on the page that has that text.
This can be achieved with xpath's contains:
//button[@class='confirmation'][contains(text(), buttonText)]
where buttonText
is the string captured by the step definition
Upvotes: 0