admin管理员组

文章数量:1389761

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

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.

Share Improve this question edited Oct 16, 2018 at 7:09 Daredevi1 asked Oct 10, 2018 at 17:03 Daredevi1Daredevi1 1033 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

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

Hope this answer helps you!

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./cucumber/cucumber-js/blob/master/docs/cli.md#Formats

本文标签: Javascript consolelog status of Cucumber scenarioStack Overflow