I have a Specflow Scenario like the following
Scenario: I Shoot a gun
When I pull the trigger
Then It should expel a bullet from the chamber
What I am wanting is to reuse this scenario like the code below
Scenario: I Shoot a gun till there are no bullets left
Given I have a fun with 2 bullets in
And I Shoot a gun
And I Shoot a gun
Then There should be no bullets left in the gun
At the minute I have to repeat all the steps in the Scenario I Shoot a gun like the following
Scenario: I Shoot a gun till there are no bullets left
Given I have a fun with 2 bullets in
When I pull the trigger
Then It should expel a bullet from the chamber
When I pull the trigger
Then It should expel a bullet from the chamber
Then There should be no bullets left in the gun
In this scenario above granted I am only saving 2 steps, but in my real life application I am saving rewriting around 20+ steps in some cases. I believe being able to call on a Scenario makes it far more easier to read and not have to worry about the hidden steps.
Is this possible in Specflow?
Because I can’t think of a reason why you want to reuse EXACTLY the same test more then once, I’m assuming you want to reuse the Scenario with different parameters. This can be done by using a Scenario Outline and Examples:
Scenario Outline: Person is supplying an address Given I am on the address page And I have entered /zipcode/ into the zipcode field And I have entered /number/ into the house_number field When I press nextStep Then I should be redirected to the confirmation page Examples: | zipcode | number | | 666 | 1 | | 666 | 2 | | 666 | 3 | | 555 | 2 |(the /’s in “/zipcode/” and “/number/” should be the ‘<‘ and ‘>’ symbols)