Reputation: 33
How do I use a step definition in a feature file where the starting keyword can be any of Given/When/Then
example:
Feature file
Given I do something
When I do something else
Then blah blah
And I do something else
How do I write just the 1 step definition to deal with the 2 x "I do something else". As far as I can tell right now I have to write 2 x identical step definitions to deal with this
Currently I have to do this in the Step Def file
[When(@"I do something else"]
public blah()
{
do something
}
[Then(@"I do something else"]
public blah2()
{
do something
}
Upvotes: 3
Views: 1116
Reputation: 5825
You can put multiple attributes on the same method.
So in your case it would look like this:
[When(@"I do something else"]
[Then(@"I do something else"]
public void blah()
{
// do something
}
If you want that a step is for all 3 parts (Given/When/Then), you can use the StepDefinitionAttribute
.
In that case it looks like this:
[StepDefinition(@"I do something else"]
public void blah()
{
// do something
}
Upvotes: 5