You can register event handlers for the following events within the cucumber lifecycle.
Event | Object |
---|---|
BeforeFeatures | array of Features |
BeforeFeature | Feature |
BeforeScenario | Scenario |
BeforeStep | Step |
StepResult | StepResult |
AfterStep | Step |
ScenarioResult | ScenarioResult |
AfterScenario | Scenario |
AfterFeature | Feature |
FeaturesResult | FeaturesResult |
AfterFeatures | array of Features |
Hooks also trigger BeforeStep
, StepResult
, and AfterStep
events with the object
HookStep
Handlers will be passed the associated object as the first argument. Handlers can be synchronous, return a promise, accept an additional callback argument, or use generators.
// features/support/handlers.js
var myHandlers = function () {
this.registerHandler('AfterFeatures', function (features, callback) {
// clean up!
// There is no World instance available on `this`
// because all scenarios are done and World instances are long gone.
callback();
});
}
module.exports = myHandlers;
Handlers timeout the same as steps / hooks and can have their timeout changed by passing in an options object.
// features/support/handlers.js
var myHandlers = function () {
this.registerHandler('AfterFeatures', {timeout: 10000}, function (features, callback) {
//...
});
}
module.exports = myHandlers;