I'm writing a method to be executed on the AfterStep
callback for Cucumber.
https://github.com/cucumber/cucumber/wiki/Hooks#step-hooks
How can I figure out which step was executed before this hook was called?
I'm writing a method to be executed on the AfterStep
callback for Cucumber.
https://github.com/cucumber/cucumber/wiki/Hooks#step-hooks
How can I figure out which step was executed before this hook was called?
Using gem cucumber 2.1.0 and scenario outlines, the scenario object in "Afterstep" is just a test result status, it does not contain the name of the step. I had to use "Before" (called before the first step) that contains a test list.
The logger is required because 'puts' only display when the scenario outline ends.
The API has been changed... Based on afterhook doc you can get the result (Cucumber::Core::Test::Result) and the step (Cucumber::Core::Test::Step) like this:
You can get the step name with:
or
Vince has a good solution, I would recommend a refactor:
You can use the @tests.count instead of the @count variable
I would have made this as comment but I don't have enough reputation yet.
I worked it out as follows:
That keeps the step number updated. In order to get the step name:
Vince's answer is great! and SMAG's refactor is cool ! but when I applied the solution on my cucumber test project, I got an error:
so, maybe the answer can update as below:
Note:
The api has changed slightly. you now need to use 'to_a'
i.e. the Alex Siri's line above would be changed to: