Cucumber-js: Can we get Scenario Name in each step of Step-Definition ?

Created on 20 Jun 2014  路  7Comments  路  Source: cucumber/cucumber-js

Most helpful comment

What is the latest and greatest way to do this now? Getting step names and such?

All 7 comments

You mean "Scenario: here is the name" - you want to retrieve it when? you can attach custom listener and during BeforeScenario event get scenario payload and on it call getName()

How do you do that? Because both of these return 'undefined'.

this.registerHandler('BeforeScenario', function (event, callback) {
  console.log(event.getPayloadItem());
  callback();
});
this.registerHandler('BeforeStep', function (event, callback) {
  console.log(event.getPayloadItem());
  callback();
});

Hi Stewart,

Have another try with this code:

// This code is generated from coffeescript so it appears a bit more verbose than needed
this.registerHandler('BeforeScenario', function (event, callback) {
    var scenario = event.getPayloadItem('scenario');
  console.info("\n[" + (scenario.getName()) + "](" + (scenario.getUri()) + ":" + (scenario.getLine()) + ")");
  callback();
});

this.registerHandler('BeforeStep', function (event, callback) {
  var step = event.getPayloadItem('step');
  console.info("\n[" + (step.getName()) + "](" + (step.getUri()) + ":" + (step.getLine()) + ")");
  callback();
});

The trick is that you need to provide an argument to getPayloadItem().

And to answer to your question, you should be able to store the current running scenario properties in an object outside of the BeforeScenario handler, then use it within the BeforeStep handler.
I hope this hints you to the right solution.

This is an issue tracker. Please post support questions to the cukes google group instead.

What is the latest and greatest way to do this now? Getting step names and such?

Bump

Was this page helpful?
0 / 5 - 0 ratings