【问题标题】:Unable to merge mochaweasome reports无法合并 mochaweasome 报告
【发布时间】:2021-12-11 19:15:32
【问题描述】:

我的测试运行器中有以下配置,并尝试将所有 mochaweasome.html 文件合并为单个 mocha 文件。

Runner.js

async function testRunner(fixture) {
  return cypress.run({
    config: {
      "reporter": "mochawesome",
      "reporterOptions": {
        "reportFilename": "sample" + `${fixture}`,
        "reportDir":"./cypress/reports/",
        "charts": true,
        "overwrite": false,
        "html": true,
        "json": true
      }
    },
    env: {
      testcaseID: `${fixture}`,
    },
    spec: './cypress/integration/' + `${param.getSpec()}` + ".spec.js",

  });
}

TestRunner.js:

const testRunner = require("./Runner.js");

const options = {
    files: [
      './cypress/reports/*.html',
    ],
  }

async function generateReport(options) {
    return merge(options).then(report => marge.create(report, options))
}

async function runner(dataSet) {
 for (let i = 0; i < dataSet.length; i += 1) {
            await setTimeout[Object.getOwnPropertySymbols(setTimeout)[0]](10000);
                try {
                    await testRunner(dataSet[i]).then((result) => {
                        console.log(JSON.stringify(result, null, " "));
                        generateReport(options);
                        if (result.runs[0].stats.failures === 1) {
                            retry.push(result.config.env.testcaseID);
                        }
                    },
                        error => {
                            generateReport(options);
                            console.error(error);
                            process.exit(1);
                        });
                }
                catch (err) {
                    process.exit(1);
                }
        }
}

测试报告的创建如下:

但它没有按照代码合并为单个报告。

谁能帮我解决这个问题。我只想要一份 mochaweasome_final 报告,其中包含一个 .html 文件中的所有结果。

更新:

使用 cypress-mochawesome-reporter 并遵循所有步骤。但是报告仍然没有合并。如何将所有 5 个 html 文件合并为一个。

输出:

【问题讨论】:

  • 你有没有把这个导入放在support/index.jsimport 'cypress-mochawesome-reporter/register';
  • 让我检查一下。

标签: javascript node.js cypress mochawesome cypress-component-test-runner


【解决方案1】:

首先,您必须使用npm i cypress-mochawesome-reporter 命令安装 mocha 报告器。

然后你必须把这个导入放在support/index.js

import 'cypress-mochawesome-reporter/register';

并将这一行导入plugin/index.js

module.exports = (on, config) => {
  require('cypress-mochawesome-reporter/plugin')(on);
};

然后在您的cypress.json 文件中

"reporter": "cypress-mochawesome-reporter",
  "reporterOptions": {
    "reportDir": "cypress/reports",
    "charts": true,
    "overwrite": false,
    "html": false,
    "json": true,
    "reportPageTitle": "My Test Suite",
    "embeddedScreenshots": true,
    "inlineAssets": true

参考:https://www.npmjs.com/package/cypress-mochawesome-reporter

【讨论】:

  • 会默认合并所有报表吗?
  • 在原始问题中添加了我更新的 cmets。你能帮我使用模块 api 将所有 html 文件合并为一个 html
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-21
  • 1970-01-01
  • 1970-01-01
  • 2016-12-22
  • 1970-01-01
  • 1970-01-01
  • 2018-09-21
相关资源
最近更新 更多