Background:
I'm currently writing behat tests (Mink/Selenium) for a Symfony2 webpage. I have a good deal of examples to go by, and actually writing them should be no problem. The step definitions are already written.
However, in the examples, they some times define a Scenario:
and some times a Scenario Outline:
Question:
What is the difference between these two ways of defining a test?
Scenario outline basically replaces variable/keywords with the value from the table. Each row in the table is considered to be a scenario. Let's continue with the same example of Facebook login feature. So far we have been executing one scenario: Upon providing the correct user name, login is successful.
Example keyword can only be used with the Scenario Outline Keyword. Scenario Outline - This is used to run the same scenario for 2 or more different sets of test data. E.g. In our scenario, if you want to register another user you can data drive the same scenario twice.
The Scenario Outline keyword can be used to run the same Scenario multiple times, with different combinations of values. The keyword Scenario Template is a synonym of the keyword Scenario Outline . We can collapse these two similar scenarios into a Scenario Outline .
Based from Gherkin Reference, the Scenario Outline keyword can be used to repeat the same steps with different values or arguments being passed to the step definitions. This is helpful if you want to test multiple arguments in the same scenario.
From the official guide:
Copying and pasting scenarios to use different values can quickly become tedious and repetitive:
Scenario: Eat 5 out of 12 Given there are 12 cucumbers When I eat 5 cucumbers Then I should have 7 cucumbers Scenario: Eat 5 out of 20 Given there are 20 cucumbers When I eat 5 cucumbers Then I should have 15 cucumbers
Scenario Outlines allow us to more concisely express these examples through the use of a template with placeholders
Scenario Outline: Eating Given there are <start> cucumbers When I eat <eat> cucumbers Then I should have <left> cucumbers Examples: | start | eat | left | | 12 | 5 | 7 | | 20 | 5 | 15 |
The Scenario Outline steps provide a template which is never directly run. A Scenario Outline is run once for each row in the Examples section beneath it (except for the first header row).
More in the Writing Features guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With