Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we get Scenario Name in each step of Step-Definition ? #200

Closed
ghost opened this issue Jun 20, 2014 · 7 comments
Closed

Can we get Scenario Name in each step of Step-Definition ? #200

ghost opened this issue Jun 20, 2014 · 7 comments

Comments

@ghost
Copy link

ghost commented Jun 20, 2014

No description provided.

@akania
Copy link
Contributor

akania commented Jun 20, 2014

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()

@Stewartarmbrecht
Copy link

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();
});

@kayhadrin
Copy link

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().

@kayhadrin
Copy link

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.

@jbpros
Copy link
Member

jbpros commented Dec 22, 2014

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

@kappa10j
Copy link

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

@Balhindi
Copy link

Bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants