归档报告,cypress.json 文件

Posted

技术标签:

【中文标题】归档报告,cypress.json 文件【英文标题】:Archiving reports, cypress.json file 【发布时间】:2021-11-12 05:43:32 【问题描述】:

我想在我的目录中存储所有新的和以前的报告。

当前行为

现在通过“npm run test”运行测试后,以前的报告被删除或附加(当我在 package.json 中删除行清理报告时)。

期望的行为

我想给我的目录路径一个动态名称,例如当前日期或编号,以便以前的路径保持原位,但我不知道是否可以在 cypres.json 中执行此操作。有什么解决办法吗?

代码

package.json

“脚本”: "clean:reports": rmdir /S /Q cypress\reports && mkdir cypress\reports && mkdircypress\reports\mochareports",

"pretest": "npm run archive-report && npm run clean:reports",

"scripts": "cypress run --browser chrome",

"combine-reports": "mochawesome-merge ./cypress/reports/chrome/mocha/*.json > cypress/reports/chrome/mochareports/report.json",

"generate-report": "marge cypress/reports/chrome/mochareports/report.json -f report -o cypress/reports/chrome/mochareports",

"posttest-chrome": "npm run combine-reports && npm run generate-report",

"test-chrome": "npm run scripts || npm run posttest-chrome"

cypress.json

"reporter": "cypress-multi-reporters",

“记者选项”:

"reporterEnabled": "mochawesome",

“mochaFile”:“raports/my-test-output-.xml”,

“mochawesomeReporterOptions”:

"reportDir": "cypress/reports/mocha",

“相当”:是的,

“覆盖”:假,

html”:假,

“json”:真

类似:ReportDir of a mochawesome reporter option in cypress.json to point to folder created at run time named after timestamp

【问题讨论】:

【参考方案1】:

解决方法: 如果您在某些 CI 中开始测试,那么一旦 npm run test 命令完成,您可以添加额外的步骤来为您执行此操作,对于 bash,它将类似于:

dirName="$(date +"%d-%m-%Y-%H:%M:%S")"
mkdir $dirName
mv cypress/screenshots/*.json $dirName

更多关于dirNamehere的细节。

【讨论】:

我想让整个过程自动化,我希望在 package.json 中可以做一些事情,例如在 posttest 中 确定:只需将“posttest”:“./posttest.sh”添加到您的package.json,并将这些命令添加到package.json旁边的posttest.sh文件中。您可能需要使用正确的路径。 我得到 ./posttest.sh '.'不被识别为内部或外部命令、可运行程序或批处理文件。 npm 错误!代码 ELIFECYCLE npm 错误! errno 1 npm 错误! cypress-tests@1.0.0 后测:./posttest.sh npm ERR!退出状态 1 npm ERR! npm 错误!在 cypress-tests@1.0.0 后测脚本中失败。 npm 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。 npm 错误!可以在以下位置找到此运行的完整日志: 如果你使用windows那么请调整命令,因为这些是linux特有的,你可以从这里开始:***.com/questions/50243229/… 感谢它的工作!我已将 "save-reports": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./posttest.ps1" 添加到 package.json 中的脚本和 posttest.ps1 命令中,例如 copy-item、rename-item

以上是关于归档报告,cypress.json 文件的主要内容,如果未能解决你的问题,请参考以下文章

Cypress Report

如何通过命令行在 cypress.json 文件中设置环境变量? (Angular CLI - nrwl nx)

Nx e2e cypress runner:来自 cypress.env.json 条目的值不会覆盖 cypress.json env 对象中的相同条目

Cypress 之 环境配置

Cypress-Cucumber 缺少步骤实现

如何获取基于 AWR 报告/存储库生成的归档日志?