Skip to content

Commit 1c68d9d

Browse files
authored
behave (#61)
1 parent a0f09e3 commit 1c68d9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1011
-137
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Feature: Background
2+
3+
Scenario Outline: Background status
4+
Given feature definition
5+
"""
6+
Feature: Background
7+
8+
Background: Scenario background with <step type> step
9+
Given <step type> step in background
10+
And another passed step in background
11+
12+
Scenario: Scenario with background contains <step type> step
13+
Given passed step
14+
And one more passed step
15+
16+
Scenario: Another scenario with background contains <step type> step
17+
Given passed step
18+
"""
19+
20+
When I run behave with allure formatter
21+
22+
Then allure report has a scenario with name "Scenario with background contains <step type> step"
23+
And this scenario has "<status>" status
24+
And this scenario has background "Scenario background with <step type> step"
25+
And this background has "<status>" status
26+
And this background contains step "Given <step type> step in background"
27+
And this step has "<status>" status
28+
And this background contains step "And another passed step in background"
29+
And this step has "<other status>" status
30+
And this scenario contains step "Given passed step"
31+
And this step has "<other status>" status
32+
And this scenario contains step "And one more passed step"
33+
And this step has "<other status>" status
34+
35+
Then allure report has a scenario with name "Another scenario with background contains <step type> step"
36+
And this scenario has "<status>" status
37+
And this scenario has background "Scenario background with <step type> step"
38+
And this scenario contains step "Given passed step"
39+
And this step has "<other status>" status
40+
41+
Examples: statuses
42+
| step type | status | other status |
43+
| passed | passed | passed |
44+
| failed | failed | skipped |
45+
| broken | broken | skipped |
46+
| undefined | broken | skipped |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@wip
2+
Feature: Description
3+
4+
Scenario: Use description
5+
Given feature definition
6+
"""
7+
Feature: Description
8+
9+
Scenario: Scenario with description
10+
Scenario description.
11+
Yep, multi-line description!
12+
13+
Given simple passed step
14+
"""
15+
When I run behave with allure formatter
16+
Then allure report has a scenario with name "Scenario with description"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Feature: Scenario
2+
3+
Scenario Outline: Scenario status
4+
Given feature definition
5+
"""
6+
Feature: Scenario
7+
8+
Scenario: Scenario with <step type> step
9+
Given <step type> step
10+
"""
11+
When I run behave with allure formatter
12+
Then allure report has a scenario with name "Scenario with <step type> step"
13+
And this scenario has "<status>" status
14+
And this scenario contains step "Given <step type> step"
15+
And this step has "<status>" status
16+
17+
Examples: statuses
18+
| step type | status |
19+
| passed | passed |
20+
| failed | failed |
21+
| broken | broken |
22+
| undefined | broken |
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Feature: Scenario Outline
2+
3+
Scenario: Scenario outline with one examples table
4+
Given feature definition
5+
"""
6+
Feature: Scenario Outline
7+
8+
Scenario Outline: Scenario outline with one examples table
9+
Given simple passed step with param "<user>"
10+
11+
Examples: examples table
12+
| user |
13+
| Alice |
14+
| Bob |
15+
"""
16+
When I run behave with allure formatter
17+
18+
Then allure report has a scenario with name "Scenario outline with one examples table"
19+
And scenario contains step "Given simple passed step with param "Alice""
20+
And this scenario has parameter "user" with value "Alice"
21+
22+
Then allure report has a scenario with name "Scenario outline with one examples table"
23+
And scenario contains step "Given simple passed step with param "Bob""
24+
And this scenario has parameter "user" with value "Bob"
25+
26+
Scenario: Scenario outline with many examples table
27+
Given feature definition
28+
"""
29+
Feature: Scenario Outline
30+
31+
Scenario Outline: Scenario outline with many examples table
32+
Given simple passed step with params "<parameter one> <parameter two>"
33+
34+
Examples: first table
35+
| parameter one | parameter two |
36+
| Peter | I |
37+
| Catherine | II |
38+
39+
Examples: second table
40+
| parameter one | parameter two |
41+
| Richard | the Lionheart |
42+
| Alexander | the Great |
43+
"""
44+
When I run behave with allure formatter
45+
46+
Then allure report has a scenario with name "Scenario outline with many examples table"
47+
And scenario contains step "Given simple passed step with params "Peter I""
48+
And this scenario has parameter "parameter one" with value "Peter"
49+
And this scenario has parameter "parameter two" with value "I"
50+
51+
Then allure report has a scenario with name "Scenario outline with many examples table"
52+
And scenario contains step "Given simple passed step with params "Catherine II""
53+
And this scenario has parameter "parameter one" with value "Catherine"
54+
And this scenario has parameter "parameter two" with value "II"
55+
56+
Then allure report has a scenario with name "Scenario outline with many examples table"
57+
And scenario contains step "Given simple passed step with params "Richard the Lionheart""
58+
And this scenario has parameter "parameter one" with value "Richard"
59+
And this scenario has parameter "parameter two" with value "the Lionheart"
60+
61+
Then allure report has a scenario with name "Scenario outline with many examples table"
62+
And scenario contains step "Given simple passed step with params "Alexander the Great""
63+
And this scenario has parameter "parameter one" with value "Alexander"
64+
And this scenario has parameter "parameter two" with value "the Great"
65+
66+
67+
Scenario: Many scenario outlines with one examples table
68+
Given feature definition
69+
"""
70+
Feature: Scenario Outline
71+
72+
Scenario Outline: First scenario outline in feature
73+
Given simple passed step with param "<friend>"
74+
75+
Examples: examples table
76+
| friend |
77+
| Rick |
78+
| Morty |
79+
80+
81+
Scenario Outline: Second scenario outline in feature
82+
Given simple passed step with param "<hero>"
83+
84+
Examples: examples table
85+
| hero |
86+
| Finn |
87+
| Jack |
88+
"""
89+
When I run behave with allure formatter
90+
91+
Then allure report has a scenario with name "First scenario outline in feature"
92+
And scenario contains step "Given simple passed step with param "Rick""
93+
And this scenario has parameter "friend" with value "Rick"
94+
95+
Then allure report has a scenario with name "First scenario outline in feature"
96+
And scenario contains step "Given simple passed step with param "Morty""
97+
And this scenario has parameter "friend" with value "Morty"
98+
99+
Then allure report has a scenario with name "Second scenario outline in feature"
100+
And scenario contains step "Given simple passed step with param "Finn""
101+
And this scenario has parameter "hero" with value "Finn"
102+
103+
Then allure report has a scenario with name "Second scenario outline in feature"
104+
And scenario contains step "Given simple passed step with param "Jack""
105+
And this scenario has parameter "hero" with value "Jack"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Feature: Severity
2+
3+
Scenario: Default severity is normal
4+
Given feature definition
5+
"""
6+
Feature: Severity
7+
8+
Scenario: Scenario and feature without severity
9+
Given simple passed step
10+
"""
11+
When I run behave with allure formatter
12+
Then allure report has a scenario with name "Scenario and feature without severity"
13+
And scenario has "normal" severity
14+
15+
16+
Scenario: Severity tag in feature
17+
Given feature definition
18+
"""
19+
@critical
20+
Feature: Severity
21+
22+
Scenario: Scenario in feature with critical severity
23+
Given simple passed step
24+
"""
25+
When I run behave with allure formatter
26+
Then allure report has a scenario with name "Scenario in feature with critical severity"
27+
And scenario has "critical" severity
28+
29+
30+
Scenario: Severity tag in scenario
31+
Given feature definition
32+
"""
33+
Feature: Severity
34+
35+
@critical
36+
Scenario: Scenario with critical severity in feature without severity
37+
Given simple passed step
38+
"""
39+
When I run behave with allure formatter
40+
Then allure report has a scenario with name "Scenario with critical severity in feature without severity"
41+
And scenario has "critical" severity
42+
43+
44+
Scenario: Severity tag in scenario and feature
45+
Given feature definition
46+
"""
47+
@critical
48+
Feature: Severity
49+
50+
@minor
51+
Scenario: Scenario with minor severity in feature with critical severity
52+
Given simple passed step
53+
"""
54+
When I run behave with allure formatter
55+
Then allure report has a scenario with name "Scenario with minor severity in feature with critical severity"
56+
And scenario has "minor" severity
57+
58+
59+
Scenario: Repeated severity tag
60+
Given feature definition
61+
"""
62+
Feature: Severity
63+
64+
@minor @critical @blocker
65+
Scenario: Scenario with repeated severity tag
66+
Given simple passed step
67+
"""
68+
When I run behave with allure formatter
69+
Then allure report has a scenario with name "Scenario with repeated severity tag"
70+
And scenario has "blocker" severity
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Feature: Step Data
2+
3+
Scenario: Step text parameter
4+
Given feature definition
5+
"""
6+
Feature: Step Data
7+
8+
Scenario: Scenario with step contains text data
9+
Given simple passed step with text data
10+
'''
11+
Some text in step
12+
'''
13+
And simple passed step
14+
"""
15+
When I run behave with allure formatter
16+
Then allure report has a scenario with name "Scenario with step contains text data"
17+
And scenario contains step "Given simple passed step with text data"
18+
And this step has attachment
19+
20+
21+
Scenario: Step table parameter
22+
Given feature definition
23+
"""
24+
Feature: Step Data
25+
26+
Scenario: Scenario with step contains table data
27+
Given simple passed step with table data
28+
| name | value |
29+
| e | 2 |
30+
| e | 4 |
31+
32+
And simple passed step
33+
"""
34+
When I run behave with allure formatter
35+
Then allure report has a scenario with name "Scenario with step contains table data"
36+
And scenario contains step "Given simple passed step with table data"
37+
And this step has attachment
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
from tempfile import mkdtemp
3+
from allure_testing.report import AllureReport
4+
from behave.parser import Parser
5+
from behave.runner import ModelRunner
6+
from behave.configuration import Configuration
7+
from behave.formatter._registry import make_formatters
8+
from behave.formatter.base import StreamOpener
9+
10+
11+
@given(u'feature definition')
12+
def feature_definition(context):
13+
parser = Parser()
14+
context.feature_definition = parser.parse(context.text)
15+
16+
17+
@when(u'I run behave with allure formatter')
18+
def run_behave_with_allure(context):
19+
cmd_args = '-v -f allure_behave.formatter:AllureFormatter -f pretty'
20+
config = Configuration(command_args=cmd_args)
21+
22+
result_tmp_dir = mkdtemp(dir=os.environ.get('TEST_TMP', None))
23+
stream_opener = StreamOpener(filename=result_tmp_dir)
24+
25+
model_runner = ModelRunner(config, [context.feature_definition])
26+
model_runner.formatters = make_formatters(config, [stream_opener])
27+
model_runner.run()
28+
29+
context.allure_report = AllureReport(result_tmp_dir)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from behave import given
2+
3+
4+
@given(u'passed step')
5+
@given(u'{what} passed step')
6+
@given(u'passed step {where}')
7+
@given(u'{what} passed step {where}')
8+
def step_impl(*args, **kwargs):
9+
pass
10+
11+
12+
@given(u'failed step')
13+
@given(u'{what} failed step')
14+
@given(u'failed step {where}')
15+
@given(u'{what} failed step {where}')
16+
def step_impl(*args, **kwargs):
17+
assert False, 'Assert message'
18+
19+
20+
@given(u'broken step')
21+
@given(u'{what} broken step')
22+
@given(u'broken step {where}')
23+
@given(u'{what} broken step {where}')
24+
def step_impl(*args, **kwargs):
25+
raise ZeroDivisionError()

0 commit comments

Comments
 (0)