You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/support_files/api_reference.md
+28-2
Original file line number
Diff line number
Diff line change
@@ -36,8 +36,8 @@ Defines a hook which is run after each scenario.
36
36
*`tags`: String tag expression used to apply this hook to only specific scenarios. See [cucumber-tag-expressions](https://docs.cucumber.io/tag-expressions/) for more information.
37
37
*`timeout`: A hook-specific timeout, to override the default timeout.
38
38
*`fn`: A function, defined as follows:
39
-
* The first argument will be an object of the form `{sourceLocation: {line, uri}, result: {duration, status, exception?}, pickle}`
40
-
* The pickle object comes from the [gherkin](https://github.com/cucumber/cucumber/tree/gherkin-v4.1.3/gherkin) library. See `testdata/good/*.pickles.ndjson` for examples of its structure.
39
+
* The first argument will be an object of the form `{pickle, gherkinDocument, result, testCaseStartedId}`
40
+
* The pickle object comes from the [gherkin](https://github.com/cucumber/cucumber/tree/gherkin/v15.0.2/gherkin) library. See `testdata/good/*.pickles.ndjson` for examples of its structure.
41
41
* When using the asynchronous callback interface, have one final argument for the callback function.
42
42
43
43
`options` can also be a string as a shorthand for specifying `tags`.
@@ -59,6 +59,24 @@ Multiple `AfterAll` hooks are executed in the **reverse** order that they are de
59
59
60
60
---
61
61
62
+
#### `AfterStep([options,] fn)`
63
+
64
+
Defines a hook which is run after each step.
65
+
66
+
*`options`: An object with the following keys:
67
+
*`tags`: String tag expression used to apply this hook to only specific scenarios. See [cucumber-tag-expressions](https://docs.cucumber.io/tag-expressions/) for more information.
68
+
*`timeout`: A hook-specific timeout, to override the default timeout.
69
+
*`fn`: A function, defined as follows:
70
+
* The first argument will be an object of the form `{pickle, gherkinDocument, result, testCaseStartedId, testStepId}`
71
+
* The pickle object comes from the [gherkin](https://github.com/cucumber/cucumber/tree/gherkin/v15.0.2/gherkin) library. See `testdata/good/*.pickles.ndjson` for examples of its structure.
72
+
* When using the asynchronous callback interface, have one final argument for the callback function.
73
+
74
+
`options` can also be a string as a shorthand for specifying `tags`.
75
+
76
+
Multiple `AfterStep` hooks are executed in the **reverse** order that they are defined.
77
+
78
+
---
79
+
62
80
#### `Before([options,] fn)`
63
81
64
82
Defines a hook which is run before each scenario. Same interface as `After` except the first argument passed to `fn` will not have the `result` property.
@@ -75,6 +93,14 @@ Multiple `BeforeAll` hooks are executed in the order that they are defined.
75
93
76
94
---
77
95
96
+
#### `BeforeStep([options,] fn)`
97
+
98
+
Defines a hook which is run before each step. Same interface as `AfterStep` except the first argument passed to `fn` will not have the `result` property.
99
+
100
+
Multiple `BeforeStep` hooks are executed in the order that they are defined.
Copy file name to clipboardExpand all lines: docs/support_files/hooks.md
+20
Original file line number
Diff line number
Diff line change
@@ -102,3 +102,23 @@ AfterAll(function () {
102
102
returnPromise.resolve()
103
103
});
104
104
```
105
+
106
+
## BeforeStep / AfterStep
107
+
108
+
If you have some code execution that needs to be done before or after all steps, use `BeforeStep` / `AfterStep`. Like the `Before` / `After` hooks, these also have a world instance as 'this', and can be conditionally selected for execution based on the tags of the scenario.
109
+
110
+
```javascript
111
+
var {AfterStep, BeforeStep} =require('cucumber');
112
+
113
+
BeforeStep({tags:"@foo"}, function () {
114
+
// This hook will be executed before all steps in a scenario with tag @foo
115
+
});
116
+
117
+
AfterStep( function ({result}) {
118
+
// This hook will be executed after all steps, and take a screenshot on step failure
0 commit comments