JSON report not generating for failed scenarios us

2019-08-27 15:23发布

If my scenarios got failed the JSON report not generating. But for passes scenarios I can able to see the JSON report.

Please find my config file as below.

enter image description here

In comment prompt console I can able to see the failure message:

W/launcher - Ignoring uncaught error AssertionError: expected false to equal true

E/launcher - BUG: launcher exited with 1 tasks remaining

1条回答
倾城 Initia
2楼-- · 2019-08-27 16:07

You can save the report by using a hook, so don't generate the file form the protractor.conf.js file, but use a cucumber-hook for it.

The hook can look like this

reportHook.js:

const cucumber = require('cucumber');
const jsonFormatter = cucumber.Listener.JsonFormatter();
const fs = require('fs-extra');
const jsonFile = require('jsonfile');
const path = require('path');
const projectRoot = process.cwd();

module.exports = function reportHook() {
  this.registerListener(jsonFormatter);

  /**
   * Generate and save the report json files
   */
  jsonFormatter.log = function(report) {
    const jsonReport = JSON.parse(report);

    // Generate a featurename without spaces, we're gonna use it later
    const featureName = jsonReport[0].name.replace(/\s+/g, '_').replace(/\W/g, '').toLowerCase();

    // Here I defined a base path to which the jsons are written to
    const snapshotPath = path.join(projectRoot, '.tmp/json-output');

    // Think about a name for the json file. I now added a featurename (each feature
    // will output a file) and a timestamp (if you use multiple browsers each browser 
    // execute each feature file and generate a report)
    const filePath = path.join(snapshotPath, `report.${featureName}.${new Date}.json`);

    // Create the path if it doesn't exists
    fs.ensureDirSync(snapshotPath);

    // Save the json file
    jsonFile.writeFileSync(filePath, jsonReport, {
      spaces: 2
    });
  };
}

You can save this code to the file reportHook.js and then add it to the cucumberOpts:.require so it will look like this in your code

cucumberOpts: {
  require: [
    '../step_definitions/*.json',
    '../setup/hooks.js',
    '../setup/reportHook.js'
  ],
  ....
}

Even with failed steps / scenario's it should generate the report file.

Hope it helps

查看更多
登录 后发表回答