1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
Feature: Scenario Description
As a tester
I want to explain the rationale of a test scenario or scenario outline
Before I actually execute the steps.
. SPECIFICATION: Scenario Description
. * Scenario descriptions are in optional section between
. Scenario line and the first step.
. * All description lines are added to the scenario description.
. * Empty lines are not part of the scenario description (are removed).
. * Comment lines are not part of the scenario description (are removed).
. * A Scenario/ScenarioOutline with a scenario description,
. but without steps is valid (to support preparation of scenarios).
.
. SPECIFICATION: A scenario description line...
. * must not start with step keywords, like:
.
. Given, When, Then, And, But, etc.
. (including lower-case versions)
.
. * must not start with '*' (ASTERISK) due to generic step keyword ambiguity
. * must not start with '@' (AT) due to tag ambiguity
. (supporting: scenario without steps but with step description).
. * may start with '|' (table-cell-separator).
. * does not contain only whitespace chars (empty line, filtered-out).
. * does not start with '#' (HASH) after whitespace chars (comment line).
.
. GRAMMAR STRUCTURE:
. Scenario-Line : 1
. Scenario-Description-Line : 0 .. N
. Step-Line : 0 .. N
.
. Scenario-Line := Scenario-Keyword ':' Scenario-Name
. Scenario-Description-Line := Line does not start with Step-Keyword
. Step-Line := Step-Keyword Words+
@setup
Scenario: Feature Setup
Given a new working directory
And a file named "features/steps/steps.py" with:
"""
from behave import step
import sys
@step('a step passes')
def step_passes(context):
pass
@step('a step passes with "{comment}"')
def step_passes(context, comment):
sys.stdout.write("PASSING-STEP: %s;\n" % comment)
@step('a step fails')
def step_fails(context):
assert False, "XFAIL-STEP"
"""
Scenario: First Example for a Scenario Description
Given a file named "features/example_description1.feature" with:
"""
Feature:
Scenario: E1
This is a simple scenario description before the steps start.
It explains why this scenario is important.
Here another scenario description line after an empty line.
Given a step passes with "Alice"
When a step passes with "Bob"
Then a step passes with "Charly"
"""
When I run "behave -f plain -T features/example_description1.feature"
Then it should pass with:
"""
1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
Feature:
Scenario: E1
Given a step passes with "Alice" ... passed
When a step passes with "Bob" ... passed
Then a step passes with "Charly" ... passed
"""
Scenario: Inspect the Scenario Description by using JSON
Given a file named "features/example_description1.feature" exists
When I run "behave -f json.pretty -o example1.json -f plain -T features/example_description1.feature"
Then it should pass
And the file "example1.json" should contain:
"""
"description": [
"This is a simple scenario description before the steps start.",
"It explains why this scenario is important.",
"Here another scenario description line after an empty line."
],
"keyword": "Scenario",
"location": "features/example_description1.feature:2",
"name": "E1",
"""
Scenario: Second Example with 2 scenario with scenario descriptions
Given a file named "features/example_description2.feature" with:
"""
@one
Feature: F2
Feature description line 1.
Feature description line 2.
@foo
Scenario: S2.1
Scenario description line S2.1-1.
Scenario description line S2.1-2 (indentation is removed).
Given a step passes with "Alice"
Then a step passes with "Charly"
@foo
@bar @baz
Scenario: S2.2
Scenario description line S2.2-1.
When a step passes with "Bob"
"""
When I run "behave -f json.pretty -o example2.json -f plain -T features/example_description2.feature"
Then it should pass with:
"""
1 feature passed, 0 failed, 0 skipped
2 scenarios passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
Feature: F2
Scenario: S2.1
Given a step passes with "Alice" ... passed
Then a step passes with "Charly" ... passed
Scenario: S2.2
When a step passes with "Bob" ... passed
"""
And the file "example2.json" should contain:
"""
"description": [
"Scenario description line S2.1-1.",
"Scenario description line S2.1-2 (indentation is removed)."
],
"keyword": "Scenario",
"location": "features/example_description2.feature:8",
"name": "S2.1",
"""
And the file "example2.json" should contain:
"""
"description": [
"Scenario description line S2.2-1."
],
"keyword": "Scenario",
"location": "features/example_description2.feature:18",
"name": "S2.2",
"""
|