Repeating BDD Tests using Scenario Outlines and an Examples table with Specflow
Today I discovered a simple yet hugely beneficial feature of Specflow (and cucumber) that before today I was unaware of.
The requirement was simple and so was the solution, once we found it.
In order to avoid repeating scenarios we wanted to be able to write a template scenario and iterate over a different set of parameters each time. Below is a simple, example of the problem as well as the solution.
Scenario: Selecting English language
Given I am on the Home page
When I select English
Then the greeting should be Hello
Scenario: Selecting German language
Given I am on the Home page
When I select Deutsch
Then the greeting should be Guten Tag
The solution was clean and simple and makes for incredibly intuitive test scripts.
Scenario Outline: Selecting a language
Given I am on the Home page
When I select <language>
Then the greeting should be <greeting>
Examples:
| language | greeting |
| English | Hello |
| Deutsch | Guten Tag |
By changing our script from a Scenario to a Scenario Outline and replacing our languages and greetings to variables, we can add an Examples table to the foot of the test which defines how many times to run the test and with which variables
If you want some further reading on using Scenario Outlines then I found the following useful: https://github.com/cucumber/cucumber/wiki/Scenario-Outlines