Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Scenario name from cucumber js?

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= ""

like image 588
rozza Avatar asked Jan 02 '23 00:01

rozza


1 Answers

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}`);
});
like image 136
rozza Avatar answered Jan 08 '23 18:01

rozza