6

As the title says, how can I find the result of a step in the AfterStep hook of cucumber.js?

Dr.Knowitall
  • 10,080
  • 23
  • 82
  • 133

2 Answers2

1

I think the question is about Cucumber.js 1.3x, which is pretty old. In Cucumber.js 3.x, there is no AfterStep hook, instead, there is a function called "setDefinitionFunctionWrapper", which can wrap a step definition, which you have chance to get the step defintion return result and manipulate it.

Here is the documentation on setDefinitionFunctionWrapper

Lean Prop
  • 111
  • 6
1

This thread is old and has an accepted answer, but since this one is outdated, I'll leave this update. Per Cucumber version 7.3.2, there is indeed an AfterStep Hook. More information about Hooks (such as that one) can be found in Hooks documentation. There is an example there about what OP queried but will share my own as well:

AfterStep(async function (step) {
    console.log(`Step status: ${step.result.status}`);
    if(step.result.status === Status.FAILED) {
        // do something
    } else if(step.result.status === Status.PASSED) {
        // do something else
    }
});
jonypera
  • 446
  • 2
  • 13
  • 23