Mon*_*1ma 2 jenkins cypress mochawesome
我正在 dockerized 容器内的 Jenkins 上运行 cypress 测试,并生成 cypress mocha 很棒的报告,但我不知道如何在 Jenkins 内显示它。
这是我的cypress.json内容
{
"integrationFolder": "test/specs",
"supportFile": "test/support/index.js",
"video": true,
"reporter": "node_modules/cypress-multi-reporters",
"reporterOptions": {
"reporterEnabled": "mochawesome",
"mochawesomeReporterOptions": {
"reportDir": "results/mocha",
"overwrite": false,
"html": false,
"json": true,
"timestamp": "mmddyyyy_HHMMss",
"showSkipped": true,
"charts": true,
"quite": true,
"embeddedScreenshots": true
}
},
"screenshotOnRunFailure": true,
"screenshotsFolder": "results/mochareports/assets/screenshots",
"videosFolder": "results/mochareports/assets/videos",
"baseUrl": "http://testurl.com",
"viewportWidth": 1920,
"viewportHeight": 1080,
"requestTimeout": 10000,
"responseTimeout": 10000,
"defaultCommandTimeout": 10000,
"watchForFileChanges": true,
"chromeWebSecurity": false
}
Run Code Online (Sandbox Code Playgroud)
这是我在本地运行的脚本。
"clean:reports": "rm -R -f results && mkdir results && mkdir results/mochareports",
"pretest": "npm run clean:reports",
"cypress:interactive": "cypress open",
"scripts:e2e": "cypress run",
"combine-reports": "mochawesome-merge results/mocha/*.json > results/mochareports/report.json",
"generate-report": "marge results/mochareports/report.json -f report -o results/mochareports -- inline",
"posttest": "npm run combine-reports && npm run generate-report",
"test:e2e": "npm run pretest && npm run scripts:e2e || npm run posttest",
Run Code Online (Sandbox Code Playgroud)
我可以在本地环境中成功查看生成的报告。这是我的jenkinsfile内容
#!groovy
pipeline {
agent any
stages {
stage('Checkout') {
steps {
echo 'Checking out the PR'
checkout scm
}
}
stage('Build') {
steps {
echo 'Destroy Old Build'
sh 'make destroy'
echo 'Building'
sh 'make upbuild_d'
}
}
stage('Test') {
steps {
echo 'Running Tests'
sh 'make test-e2e'
}
}
stage('Destroy') {
steps {
echo 'Destroy Build'
sh 'make destroy'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
实际上在 docker 容器内make test-e2e运行test:e2e脚本,测试实际运行,我可以看到 Jenkins 上生成的报告,但我不知道如何查看它。

我需要在 Jenkins 内部单独查看它,我也不知道为什么我无法通过Jenkins workspace. 顺便提一句。我将结果文件添加到.gitignore
小智 5
您可以使用 Jenkins 的 HTML 发布者插件来实现此目的:
https://plugins.jenkins.io/htmlpublisher/
在 Jenkinsfile 中添加一个阶段来发布 HTML 报告
例如
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'cypress/cypress/reports/html',
reportFiles: 'index.html',
reportName: 'HTML Report',
reportTitles: ''])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6630 次 |
| 最近记录: |