In case of error I want to be able to log the scenario name. I'm using cucumber.js and node.
Feature file
Scenario: As me I can go to google
Given that I have a computer
When I go to google
Then I see wondrous stuff
I have tried the code below, but the name comes back as an empty string.
When(/^I go to google$/, (scenario) => {
// do something
var scenarioName = scenario.name;
});
By stepping through the code I can see that it's a function. It has :
[[FunctionLocation]] = Object
[[Scopes]] = Scopes(6)
length = 2
name= ""
It seems like you can't do this in a Given or When, it has to be done in the Before or After hook:
Before((scenario) => {
const scenarioName = scenario.name;
console.log(`${scenarioName}`);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With