简体   繁体   中英

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.

Below should work- (tried with wdio-cucumber)

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

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

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

Hope this answer helps you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM