I was wondering if it would be possible to write generic step_definitions in cucumber, that can be used for a Given, When or Then scenario when needed. For example:
Given the browser is started
When I navigate to my webpage
Then the element with id login is present
Given the element with id login is present
When I press the button
Then something should happen
In this case, I would like to create one step_definition for the element with id login is present that can be used in the Given and the Then clause.
Using Javascript, I can type:
defineSupportCode(({ Given, Then }) => {
Then(/^Element with id (.+) is present$/, (name) => {
return client.expect.element("#" + name).to.be.present;
});
});
Although this seems to work if I provide Given and Then in the defineSupportCode (even though I don't understand why), it feels not right to specify the step itself as a Then. I would prefer to define it as Generic or anything like that. Of course I could write the Scenario as:
* the element with id login is present
but that's something I actually dislike as well. Am I missing something here?