Reputation: 71
I have a problem with generate scenario in Specflow, with AND word
Scenario contains And
phrase, but after Generate Step Definition Skeleton it change to When
.
Upvotes: 1
Views: 480
Reputation: 2063
The (auto steps generator) SpecFlow detects that the first two sentences are the same, except the numbers that are considers parameters. Try to add the word "first" to the first sentence and the word "second" to the second sentence and regenerate the step definition. Actually you can add any word that differentiate the first sentence from the second.:
Scenario: Add two numbers
Given I have entered first 50 into the calculator
And I have entered second 70 into the calculator
When I press add
Then the result should be 120 on the screen
You will get a new step but you won't see the And
attribute in the steps. It looks like StepDefinitionBaseAttribute
(which is implemented by WhenAttribute
) has no And
attribute implemented and the use of it is only in the Gherkin file for readability.
Note that Specflow doesn't care whether you name a step Given
, When
or Then
but it should match an expression in the steps and used for readability. The order does matter.
Upvotes: 1
Reputation: 3890
Its all absolutely correct. Specflow is a BDD approach that uses keywords: GIVEN, WHEN, THEN.
When your GIVEN
condition is more complex (more steps) you can use AND
keyword but still step itself is GIVEN
one. Thanks to that you can use same steps in multiple tests and chains as long as GIVEN
, WHEN
, THEN
keyword fits.
Furthermore, if you want to have one step definition used in multiple keywords you can mark that step with attribute of GIVEN
, WHEN
, THEN
at the same time to avoid code repetition.
Also Specflow lets you pass parameters from feature file into step definition. So you could merge first two steps in one.
Upvotes: 0