首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在失败时生成黄瓜HTML报告

无法在失败时生成黄瓜HTML报告
EN

Stack Overflow用户
提问于 2022-02-21 07:34:04
回答 2查看 1.3K关注 0票数 0

我创建了一个使用类型记录和Cucumber BDD方法的项目框架。项目中的执行正在工作,当执行被传递时也会生成黄瓜html报告,但是当事情由于某种原因(在我的例子中是否断言原因)而失败时,报告不会在指定的文件夹中生成。

下面是一些需要注意的要点;

  • I正在使用package.json测试模块执行我的执行。

代码语言:javascript
复制
{
  "name": "sampleprojectplaywright",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    
    "test": "cucumber-js features/**/*.feature --require-module ts-node/register --require test.setup.ts --require step-definitions/**/*.ts --parallel 1 -f json:report/report.json && node report.js && type report/report.json"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@cucumber/cucumber": "^7.3.2",
    "@playwright/test": "^1.19.1",
    "@types/mkdirp": "^1.0.2",
    "@types/node": "^17.0.18",
    "cucumber-html-reporter": "^5.3.0",
    "cucumber-junit": "^1.7.1",
    "cucumberjs-junitxml": "^1.0.0",
    "fs-extra": "^3.0.1",
    "mkdirp": "^0.5.1",
    "mkdirp-promise": "^5.0.1",
    "multiple-cucumber-html-reporter": "^1.19.0",
    "playwright": "^1.19.1",
    "sanitize-filename": "^1.6.1",
    "ts-node": "^10.5.0",
    "typescript": "^4.5.5"
  }
}

下面的

  • report.js文件的代码片段(在那里的文件夹中生成报告)

代码语言:javascript
复制
const reporter = require("cucumber-html-reporter");
const options = {
  theme: "bootstrap",
  jsonFile: "report/report.json",
  output: "report/cucumber-html-report.html",
  reportSuiteAsScenarios: true,
  launchReport: false,
};
reporter.generate(options);

需要考虑的一点是,report.json也是在失败的情况下被创建的,但是只有html报告没有在失败时创建。

EN

回答 2

Stack Overflow用户

发布于 2022-05-14 05:47:38

为了生成失败的html报告,请尝试在cucumber.js文件中添加下面的代码。

在常见的添加“

供参考

代码语言:javascript
复制
const common = --require runner/hooks.js --require features/support/steps.js --require report.js;

module.exports = {
default: ${common} features/**/*.feature
};
票数 0
EN

Stack Overflow用户

发布于 2022-09-08 14:08:17

您的test脚本正在运行命令cucumber-js features/**/*.feature --require-module ts-node/register --require test.setup.ts --require step-definitions/**/*.ts --parallel 1 -f json:report/report.json

和generate报表命令node report.js

在使用&&时,generate命令只有在前面的命令成功时才会运行。由于测试失败,黄瓜-js退出代码为1,并且不执行generate命令。

解决方案:将&&替换为;,它应该生成报告,而不管测试的结果如何。

代码语言:javascript
复制
"test": "cucumber-js features/**/*.feature --require-module ts-node/register --require test.setup.ts --require step-definitions/**/*.ts --parallel 1 -f json:report/report.json; node report.js; type report/report.json"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71202647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档