22

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?

Wouter J
  • 41,455
  • 15
  • 107
  • 112
Alec
  • 1,986
  • 4
  • 23
  • 47

2 Answers2

40

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.

dziobaczy
  • 891
  • 9
  • 17
Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125
  • Do i have to have the simple `Scenario` when i have `Scenario Outlet`? – Sal-laS May 07 '17 at 19:46
  • 1
    @Salman no. `Scenario Outline` is simply a scenario with a set of examples. Whenever you need to use the `Examples` section, you need to use the `Scenario Outline` instead of a `Scenario`. The difference is that a `Scenario` will be executed once while `Scenario Outline` is executed for each example from the table. – Jakub Zalas May 08 '17 at 14:38
  • 1
    A new link on guide for writing scenarios can be found at: https://docs.behat.org/en/latest/user_guide/writing_scenarios.html – dziobaczy Feb 08 '21 at 23:13
  • It seems like it should be possible to autodetect this. This is an unnecessary source of mistakes. From what I can see, cucumber.js correctly handles examples, even if you write only 'Scenario' – Post Self May 27 '22 at 08:32
  • @PostSelf If this is something that the original Cucumber supports, I'm sure Behat maintainers would accept your pull request to support it in their project as well. – Jakub Zalas Jun 23 '22 at 19:53
-1

Scenario is what it is.

Scenario outline uses placeholders for faster testing.

https://github.com/cucumber/cucumber/wiki/Scenario-Outlines

Siim Kallari
  • 851
  • 6
  • 17