Daredevi1
Daredevi1

Reputation: 103

Javascript console.log status of Cucumber scenario

I would like to print the status of each cucumber scenario using the afterScenario hook.

I've tried printing out scenario.status (code below) but it prints out "undefined"

afterScenario: (scenario) => {
    console.log(scenario.status);
}

When printing out just scenario, I don't see status.

Scenario {
  feature: 
   Feature {
     description: undefined,
     keyword: 'Feature',
     line: 1,
     name: 'Sample Test',
     tags: [],
     uri: '/Users/Daredevil/e2e/features/sampleProject/intro.feature',
     scenarios: [ [Circular] ] },
  keyword: 'Scenario',
  lines: [ 15, 7 ],
  name: 'Getting test status',
  tags: 
   [ Tag { line: 6, name: '@WIP' }],
  uri: '/Users/Daredevil/e2e/features/sampleProject/intro.feature',
  line: 15,
  description: undefined,
  steps: 
   [ Step {
       arguments: [],
       line: 4,
       name: 'I am on the app',
       scenario: [Circular],
       uri: '/Users/Daredevil/e2e/features/sampleProject/intro.feature',
       isBackground: true,
       keyword: 'Given ',
       keywordType: 'precondition' },
     Step {
       arguments: [],
       line: 8,
       name: 'I am viewing the splash screen',
       scenario: [Circular],
       uri: '/Users/Daredevil/e2e/features/sampleProject/intro.feature',
       isBackground: false,
       keyword: 'Given ',
       keywordType: 'precondition' } ] }

I had a read through https://docs.cucumber.io/cucumber/api/#hooks which suggested (from my understanding) to do scenario.failed, but I still get undefined. Would anyone be able to tell me how I can get the status of a scenario?

I am using cucumber v3.2.1 and wdio-cucumber-framework v1.0.3.

Upvotes: 2

Views: 9515

Answers (3)

janv
janv

Reputation: 191

Answer is simple, you should be console logging "scenario.result.status" instead of scenario.status.

Hope this answer helps you!

Upvotes: 1

Ray
Ray

Reputation: 1214

This is not an answer just a suggestion. I would look into how the report.json is built as that report has all the scenarios and their result.

Another pointer is in your cucumber.js file set the reporting format you want to progress which will output progress to the console.

Take a look at https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#Formats

Upvotes: 0

Aparna
Aparna

Reputation: 79

Below should work- (tried with wdio-cucumber)

After(function (scenarioResult) {
        const scenario = scenarioResult.scenario;
        console.log('SCENARIO EXECUTION COMPLETED:',scenario.name);
    });

Upvotes: 1

Related Questions