在cypress中将测试结果导出为HTML

soc*_*way 5 javascript cypress

有什么方法test results可以将 Cypress 导出为 HTML 或任何其他格式(如 cucumber-report.html

Ste*_*i J 14

您可以使用mochawesomereporter运行来导出报告。但需要注意的是,当单独使用时,会生成单独的报告,这些报告会被运行的最新规范文件覆盖。为了合并所有单独的mochawesome报告,请尝试mochawesome-merge合并所有测试结果并将其导出为 HTML。

\n

为此,

\n
    \n
  1. 安装mochamochawesome并且mochawesome-merge(mochawesome 对 mocha 有对等依赖)
  2. \n
\n
\n
npm install mocha\nnpm install mochawesome --save-dev\nnpm install mochawesome-merge --save-dev\n
Run Code Online (Sandbox Code Playgroud)\n
\n
    \n
  1. 在 中cypress.json,粘贴以下配置:
  2. \n
\n
\n
\n
{\n      "reporter": "mochawesome",\n     "reporterOptions": {\n       "charts": true,\n       "overwrite": false,\n       "html": false,\n       "json": true,\n       "reportDir": "cypress/report/mochawesome-report"\n      }\n    }\n
Run Code Online (Sandbox Code Playgroud)\n
    \n
  1. 运行赛普拉斯
  2. \n
\n
\n

npx cypress run --reporter mochawesome

\n
\n
    \n
  1. 运行所有测试后,将报告合并为一份报告
  2. \n
\n
\n

npx mochawesome-merge cypress/report/mochawesome-report/*.json > cypress/report/output.json

\n
\n
    \n
  1. 现在将 JSON 转换为 HTML
  2. \n
\n
\n

npx marge cypress/report/output.json --reportDir ./ --inline

\n
\n
    \n
  1. 生成 HTML 报告后,您将看到如下内容:
  2. \n
\n
\n

\xe2\x9c\x93 已保存的报告:\nE:\\Project_Path\\cypress\\report\\output.html

\n
\n

  • 此外,后续运行会生成重复的 json(内容相同,但后缀为“_001”),这将导致测试在 HTML 上显示两次。也许您需要边缘拉夫步? (2认同)