-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathbefore_after_step_hooks.feature
95 lines (83 loc) · 2.63 KB
/
before_after_step_hooks.feature
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
Feature: Before and After Step Hooks
Background:
Given a file named "features/a.feature" with:
"""
Feature: some feature
@this-tag
Scenario: some scenario
Given a step
"""
And a file named "features/step_definitions/cucumber_steps.js" with:
"""
const {Given} = require('@cucumber/cucumber')
Given(/^a step$/, function() {})
"""
Scenario: Before and After Hooks work correctly
Given a file named "features/support/hooks.js" with:
"""
const {BeforeStep, AfterStep, BeforeAll, AfterAll} = require('@cucumber/cucumber')
const {expect} = require('chai')
let counter = 1
BeforeStep(function() {
counter = counter + 1
})
AfterStep(function() {
expect(counter).to.eql(2)
counter = counter + 1
})
AfterAll(function() {
expect(counter).to.eql(3)
})
"""
When I run cucumber-js
Then it passes
Scenario: Failing before step fails the scenario
Given a file named "features/support/hooks.js" with:
"""
const {BeforeStep} = require('@cucumber/cucumber')
BeforeStep(function() { throw 'Fail' })
"""
When I run cucumber-js
Then it fails
Scenario: Failing after step fails the scenario
Given a file named "features/support/hooks.js" with:
"""
const {AfterStep} = require('@cucumber/cucumber')
AfterStep(function() { throw 'Fail' })
"""
When I run cucumber-js
Then it fails
Scenario: Only run BeforeStep hooks with appropriate tags
Given a file named "features/support/hooks.js" with:
"""
const { BeforeStep } = require('@cucumber/cucumber')
BeforeStep({tags: "@any-tag"}, function() {
throw Error("Would fail if ran")
})
"""
When I run cucumber-js
Then it passes
Scenario: Only run BeforeStep hooks with appropriate tags
Given a file named "features/support/hooks.js" with:
"""
const { AfterStep } = require('@cucumber/cucumber')
AfterStep({tags: "@this-tag"}, function() {
throw Error("Would fail if ran")
})
"""
When I run cucumber-js
Then it fails
Scenario: after hook parameter can access result status of step
Given a file named "features/support/hooks.js" with:
"""
const { AfterStep, Status } = require('@cucumber/cucumber')
AfterStep(function({result}) {
if (result.status === Status.PASSED) {
return
} else {
throw Error("Result object did not get passed properly to AfterStep Hook.")
}
})
"""
When I run cucumber-js
Then it passes