Debian Codegraph @

features/formatter.json.feature

raw
1 @sequential
2 Feature: JSON Formatter
3
4 In order to process data with other tools
5 As a tester
6 I want that behave generates test run data in JSON format.
7
8
9 @setup
10 Scenario: Feature Setup
11 Given a new working directory
12 And a file named "features/steps/steps.py" with:
13 """
14 from behave import step
15
16 @step('a step passes')
17 def step_passes(context):
18 pass
19
20 @step('a step fails')
21 def step_fails(context):
22 assert False, "XFAIL-STEP"
23 """
24
25 Scenario: Use JSON formatter on simple feature
26 Given a file named "features/simple_feature_with_name.feature" with:
27 """
28 Feature: Simple, empty Feature
29 """
30 When I run "behave -f json.pretty features/simple_feature_with_name.feature"
31 Then it should pass with:
32 """
33 0 features passed, 0 failed, 1 skipped
34 0 scenarios passed, 0 failed, 0 skipped
35 """
36 And the command output should contain:
37 """
38 [
39 {
40 "keyword": "Feature",
41 "location": "features/simple_feature_with_name.feature:1",
42 "name": "Simple, empty Feature",
43 "status": "skipped",
44 "tags": []
45 }
46 ]
47 """
48
49 Scenario: Use JSON formatter on simple feature with description
50 Given a file named "features/simple_feature_with_description.feature" with:
51 """
52 Feature: Simple feature with description
53
54 First feature description line.
55 Second feature description line.
56
57 Third feature description line (following an empty line).
58 """
59 When I run "behave -f json.pretty features/simple_feature_with_description.feature"
60 Then it should pass with:
61 """
62 0 features passed, 0 failed, 1 skipped
63 0 scenarios passed, 0 failed, 0 skipped
64 """
65 And the command output should contain:
66 """
67 [
68 {
69 "description": [
70 "First feature description line.",
71 "Second feature description line.",
72 "Third feature description line (following an empty line)."
73 ],
74 "keyword": "Feature",
75 "location": "features/simple_feature_with_description.feature:1",
76 "name": "Simple feature with description",
77 "status": "skipped",
78 "tags": []
79 }
80 ]
81 """
82
83 Scenario: Use JSON formatter on simple feature with tags
84 Given a file named "features/simple_feature_with_tags.feature" with:
85 """
86 @foo @bar
87 Feature: Simple feature with tags
88 """
89 When I run "behave -f json.pretty features/simple_feature_with_tags.feature"
90 Then it should pass with:
91 """
92 0 features passed, 0 failed, 1 skipped
93 0 scenarios passed, 0 failed, 0 skipped
94 """
95 And the command output should contain:
96 """
97 [
98 {
99 "keyword": "Feature",
100 "location": "features/simple_feature_with_tags.feature:2",
101 "name": "Simple feature with tags",
102 "status": "skipped",
103 "tags": [
104 "foo",
105 "bar"
106 ]
107 }
108 ]
109 """
110
111 Scenario: Use JSON formatter with feature and one scenario without steps
112 Given a file named "features/simple_scenario.feature" with:
113 """
114 Feature:
115 Scenario: Simple scenario without steps
116 """
117 When I run "behave -f json.pretty features/simple_scenario.feature"
118 Then it should pass with:
119 """
120 1 feature passed, 0 failed, 0 skipped
121 1 scenario passed, 0 failed, 0 skipped
122 """
123 And the command output should contain:
124 """
125 [
126 {
127 "elements": [
128 {
129 "keyword": "Scenario",
130 "location": "features/simple_scenario.feature:2",
131 "name": "Simple scenario without steps",
132 "status": "passed",
133 "steps": [],
134 "tags": [],
135 "type": "scenario"
136 }
137 ],
138 "keyword": "Feature",
139 "location": "features/simple_scenario.feature:1",
140 "name": "",
141 "status": "passed",
142 "tags": []
143 }
144 ]
145 """
146
147 Scenario: Use JSON formatter with feature and one scenario with description
148 Given a file named "features/simple_scenario_with_description.feature" with:
149 """
150 Feature:
151 Scenario: Simple scenario with description but without steps
152
153 First scenario description line.
154 Second scenario description line.
155
156 Third scenario description line (after an empty line).
157 """
158 When I run "behave -f json.pretty features/simple_scenario_with_description.feature"
159 Then it should pass with:
160 """
161 1 feature passed, 0 failed, 0 skipped
162 1 scenario passed, 0 failed, 0 skipped
163 """
164 And the command output should contain:
165 """
166 [
167 {
168 "elements": [
169 {
170 "description": [
171 "First scenario description line.",
172 "Second scenario description line.",
173 "Third scenario description line (after an empty line)."
174 ],
175 "keyword": "Scenario",
176 "location": "features/simple_scenario_with_description.feature:2",
177 "name": "Simple scenario with description but without steps",
178 "status": "passed",
179 "steps": [],
180 "tags": [],
181 "type": "scenario"
182 }
183 ],
184 "keyword": "Feature",
185 "location": "features/simple_scenario_with_description.feature:1",
186 "name": "",
187 "status": "passed",
188 "tags": []
189 }
190 ]
191 """
192
193 Scenario: Use JSON formatter with feature and one scenario with tags
194 Given a file named "features/simple_scenario_with_tags.feature" with:
195 """
196 Feature:
197
198 @foo
199 @bar
200 Scenario: Simple scenario with tags but without steps
201 """
202 When I run "behave -f json.pretty features/simple_scenario_with_tags.feature"
203 Then it should pass with:
204 """
205 1 feature passed, 0 failed, 0 skipped
206 1 scenario passed, 0 failed, 0 skipped
207 """
208 And the command output should contain:
209 """
210 [
211 {
212 "elements": [
213 {
214 "keyword": "Scenario",
215 "location": "features/simple_scenario_with_tags.feature:5",
216 "name": "Simple scenario with tags but without steps",
217 "status": "passed",
218 "steps": [],
219 "tags": [
220 "foo",
221 "bar"
222 ],
223 "type": "scenario"
224 }
225 ],
226 "keyword": "Feature",
227 "location": "features/simple_scenario_with_tags.feature:1",
228 "name": "",
229 "status": "passed",
230 "tags": []
231 }
232 ]
233 """
234
235
236 Scenario: Use JSON formatter with type-converted step parameters
237
238 Ensure that step parameters (match arguments) leads to valid JSON
239 even when type converters are used which create non-simple types.
240
241 Given a file named "features/step_params_with_type_converter.feature" with:
242 """
243 Feature:
244 Scenario: Use type converter
245 Given "1+2j" as complex number
246 And "red" as color
247 """
248 And a file named "features/steps/type_converter_steps.py" with:
249 """
250 from behave import step, register_type
251 import parse
252
253 # -- TYPES AND TYPE CONVERTERS:
254 class Color(object):
255 def __init__(self, color_name):
256 self.name = color_name
257
258 @parse.with_pattern("\w+")
259 def parse_color(text):
260 return Color(text.strip())
261
262 @parse.with_pattern(".+")
263 def parse_complex(text):
264 return complex(text)
265
266 register_type(Color=parse_color)
267 register_type(Complex=parse_complex)
268
269 # -- STEPS:
270 @step('"{number:Complex}" as complex number')
271 def step_complex_number(context, number):
272 context.number = number
273
274 @step('"{color:Color}" as color')
275 def step_color(context, color):
276 context.color = color
277 """
278 When I run "behave -f json.pretty features/step_params_with_type_converter.feature"
279 Then it should pass with:
280 """
281 1 scenario passed, 0 failed, 0 skipped
282 """
283 And the command output should contain:
284 """
285 "match": {
286 "arguments": [
287 {
288 "name": "number",
289 "value": "1+2j"
290 }
291 ],
292 "location": "features/steps/type_converter_steps.py:21"
293 },
294 "name": "\"1+2j\" as complex number",
295 """
296 And the command output should contain:
297 """
298 "match": {
299 "arguments": [
300 {
301 "name": "color",
302 "value": "red"
303 }
304 ],
305 "location": "features/steps/type_converter_steps.py:25"
306 },
307 "name": "\"red\" as color",
308 """
309 But note that "both matched arguments.values are provided as string"
310
311
312 @xfail
313 @regression_problem.with_duration
314 Scenario: Use JSON formatter with feature and one scenario with steps
315 Given a file named "features/scenario_with_steps.feature" with:
316 """
317 Feature:
318 Scenario: Simple scenario with with steps
319 Given a step passes
320 When a step passes
321 Then a step passes
322 And a step passes
323 But a step passes
324 """
325 When I run "behave -f json.pretty features/scenario_with_steps.feature"
326 Then it should pass with:
327 """
328 1 feature passed, 0 failed, 0 skipped
329 1 scenario passed, 0 failed, 0 skipped
330 """
331 And the command output should contain:
332 """
333 "steps": [
334 {
335 "keyword": "Given",
336 "location": "features/scenario_with_steps.feature:2",
337 "match": {
338 "arguments": [],
339 "location": "features/steps/steps.py:3"
340 },
341 "name": "a step passes",
342 "result": {
343 "duration": XXX,
344 "status": "passed",
345 }
346 "step_type": "given",
347 },
348 {
349 "keyword": "When",
350 "location": "features/scenario_with_steps.feature:3",
351 "match": {
352 "arguments": [],
353 "location": "features/steps/steps.py:3"
354 },
355 "name": "a step passes",
356 "result": {
357 "duration": XXX,
358 "status": "passed",
359 }
360 "step_type": "when",
361 },
362 {
363 "keyword": "Then",
364 "location": "features/scenario_with_steps.feature:4",
365 "match": {
366 "arguments": [],
367 "location": "features/steps/steps.py:3"
368 },
369 "name": "a step passes",
370 "result": {
371 "duration": XXX,
372 "status": "passed",
373 }
374 "step_type": "then",
375 },
376 {
377 "keyword": "And",
378 "location": "features/scenario_with_steps.feature:5",
379 "match": {
380 "arguments": [],
381 "location": "features/steps/steps.py:3"
382 },
383 "name": "a step passes",
384 "result": {
385 "duration": XXX,
386 "status": "passed",
387 }
388 "step_type": "then",
389 },
390 {
391 "keyword": "But",
392 "location": "features/scenario_with_steps.feature:6",
393 "match": {
394 "arguments": [],
395 "location": "features/steps/steps.py:3"
396 },
397 "name": "a step passes",
398 "result": {
399 "duration": XXX,
400 "status": "passed",
401 }
402 "step_type": "then",
403 }
404 ],
405 """
406
407 @wip
408 Scenario: Use JSON formatter with feature and two scenarios
409
410 @wip
411 Scenario: Use JSON formatter with feature and background
412
413 @wip
414 Scenario: Use JSON formatter with feature and scenario outline without steps
415 Scenario: Use JSON formatter with feature and scenario outline with description
416 Scenario: Use JSON formatter with feature and scenario outline with tags
417 Scenario: Use JSON formatter with feature and scenario outline with steps
418 Scenario: Use JSON formatter with feature and scenario outline with steps and examples
419
420