2
Feature: Scenario outlines
4
Copying and pasting scenarios to use different values quickly
5
becomes tedious and repetitive. Scenario outlines allow us to more
6
concisely express these examples through the use of a template with
7
placeholders, using Scenario Outline, Examples with tables and < >
10
The Scenario Outline steps provide a template which is never directly
11
run. A Scenario Outline is run once for each row in the Examples section
12
beneath it (not counting the first row).
14
The way this works is via placeholders. Placeholders must be contained
15
within < > in the Scenario Outline's steps - see the examples below.
17
**IMPORTANT:** Your step definitions will never have to match a
18
placeholder. They will need to match the values that will replace the
22
Given a file named "features/outline_sample.feature" with:
24
Feature: Outline Sample
26
Scenario: I have no steps
28
Scenario Outline: Test state
29
Given <state> without a table
30
Given <other_state> without a table
31
Examples: Rainbow colours
32
| state | other_state |
37
| state | other_state |
40
And a file named "features/step_definitions/steps.rb" with:
42
Given(/^passing without a table$/) { }
43
Given(/^failing without a table$/) { raise RuntimeError }
46
Scenario: Run scenario outline with filtering on outline name
47
When I run `cucumber -q features/outline_sample.feature`
48
Then it should fail with:
50
Feature: Outline Sample
52
Scenario: I have no steps
54
Scenario Outline: Test state
55
Given <state> without a table
56
Given <other_state> without a table
58
Examples: Rainbow colours
59
| state | other_state |
63
RuntimeError (RuntimeError)
64
./features/step_definitions/steps.rb:2:in `/^failing without a table$/'
65
features/outline_sample.feature:12:in `Given failing without a table'
66
features/outline_sample.feature:6:in `Given <state> without a table'
68
Examples: Only passing
69
| state | other_state |
73
cucumber features/outline_sample.feature:12
75
5 scenarios (1 failed, 1 undefined, 3 passed)
76
8 steps (1 failed, 2 skipped, 1 undefined, 4 passed)
79
Scenario: Run scenario outline steps only
80
When I run `cucumber -q features/outline_sample.feature:7`
81
Then it should fail with:
83
Feature: Outline Sample
85
Scenario Outline: Test state
86
Given <state> without a table
87
Given <other_state> without a table
89
Examples: Rainbow colours
90
| state | other_state |
94
RuntimeError (RuntimeError)
95
./features/step_definitions/steps.rb:2:in `/^failing without a table$/'
96
features/outline_sample.feature:12:in `Given failing without a table'
97
features/outline_sample.feature:6:in `Given <state> without a table'
99
Examples: Only passing
100
| state | other_state |
101
| passing | passing |
104
cucumber features/outline_sample.feature:12
106
4 scenarios (1 failed, 1 undefined, 2 passed)
107
8 steps (1 failed, 2 skipped, 1 undefined, 4 passed)
111
Scenario: Run single failing scenario outline table row
112
When I run `cucumber -q features/outline_sample.feature:12`
113
Then it should fail with:
115
Feature: Outline Sample
117
Scenario Outline: Test state
118
Given <state> without a table
119
Given <other_state> without a table
121
Examples: Rainbow colours
122
| state | other_state |
123
| failing | passing |
124
RuntimeError (RuntimeError)
125
./features/step_definitions/steps.rb:2:in `/^failing without a table$/'
126
features/outline_sample.feature:12:in `Given failing without a table'
127
features/outline_sample.feature:6:in `Given <state> without a table'
130
cucumber features/outline_sample.feature:12
132
1 scenario (1 failed)
133
2 steps (1 failed, 1 skipped)
137
Scenario: Run all with progress formatter
138
When I run `cucumber -q --format progress features/outline_sample.feature`
139
Then it should fail with exactly:
143
(::) failed steps (::)
145
RuntimeError (RuntimeError)
146
./features/step_definitions/steps.rb:2:in `/^failing without a table$/'
147
features/outline_sample.feature:12:in `Given failing without a table'
148
features/outline_sample.feature:6:in `Given <state> without a table'
151
cucumber features/outline_sample.feature:12
153
5 scenarios (1 failed, 1 undefined, 3 passed)
154
8 steps (1 failed, 2 skipped, 1 undefined, 4 passed)