使用量角器未针对失败场景生成 JSON 报告 [英] JSON report not generating for failed scenarios using protractor

查看:17
本文介绍了使用量角器未针对失败场景生成 JSON 报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的方案失败,则不会生成 JSON 报告.但是对于通行证场景,我可以看到 JSON 报告.

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.

在评论提示控制台中我可以看到失败消息:

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

W/launcher - 忽略未捕获的错误 AssertionError:预期 false 等于 true

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

E/launcher - BUG:启动器退出,剩余 1 个任务

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

推荐答案

你可以使用钩子保存报告,所以不要从protractor.conf.js文件生成文件,但要使用黄瓜钩.

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.

钩子可以是这样的

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

您可以将此代码保存到文件 reportHook.js 中,然后将其添加到 cucumberOpts:.require 中,以便在您的代码中看起来像这样

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.

希望对你有帮助

这篇关于使用量角器未针对失败场景生成 JSON 报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆