azure - 为什么赛普拉斯和 Azure DevOps 的测试自动化只能部分成功?
问题描述
我正在使用 Cypress.io(版本 5.1.0)来测试我的项目。我的项目在 azure DevOps 中。现在我想在 Azure DevOps 中包含我的 cypress 测试,这样我的测试就会自动运行。
我在我的赛普拉斯项目中设置了 JUnit 报告器:在我添加的“package.json”文件中
"cypress-multi-reporters": "^1.2.4",
"mocha-junit-reporter": "^1.23.3"
然后运行 npm install
比添加
"scripts": {
"scripts": "cypress run",
"test": "npm run scripts"
}
我添加到我的“cypress.json”文件中
"reporter": "mocha-junit-reporter",
"reporterOptions": {
"mochaFile": "cypress/reports/junit/test-results.[hash].xml",
"testsuitesTitle": false
}
在此之后,我在 Azure DevOps 中使用 Azure Repos 创建了一个新管道。对于管道配置,我选择了 Node.js。
现在我有一个 YAML 文件。在这里,我 npm build
从第一个脚本中删除。
现在我从助手那里选择了 npm。在 npm 配置中,我选择custom
并编写了 command run test
。现在我选择结果格式为“JUnit”并将测试结果文件设置为“*.xml” 最后我选择了“合并测试结果”选项。现在我保存并运行管道。
这就是我的工作所做的:
Pool: Azure Pipelines
Image: ubuntu-latest
Agent: Hosted Agent
Started: Yesterday at 17:31
Expanded: Object
Result: True
Evaluating: not(containsValue(job['steps']['*']['task']['id'], '6d15af64-176c-496d-b583-fd2ae21d4df4'))
Expanded: not(containsValue(Object, '6d15af64-176c-496d-b583-fd2ae21d4df4'))
Result: True
Evaluating: resources['repositories']['self']['checkoutOptions']
Result: Object
Finished evaluating template 'system-pre-steps.yml'
********************************************************************************
Template and static variable resolution complete. Final runtime YAML document:
steps:
- task: 6d15af64-176c-496d-b583-fd2ae21d4df4@1
inputs:
repository: self
MaxConcurrency: 0
我的自动化出了什么问题?我怎样才能解决这个问题?
更新:那是我的 yml 文件:
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
displayName: 'npm install'
- task: Npm@1
inputs:
command: 'custom'
customCommand: 'run test'
continueOnError: true
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/cypress/reports/junit'
mergeTestResults: true
testRunTitle: 'Publish Test Results'
我收到一封包含此详细信息的电子邮件
作业 1 错误,1 警告错误:Npm 失败,返回码:254
解决方案
如前所述,问题很可能出在 Azure 环境中。赛普拉斯依赖于浏览器(电子、铬)才能执行。例如,如果您使用 docker,他们会提供一个名为cypress/browsers:node14.7.0-chrome84的官方镜像,其中包含您需要的所有内容。Dockerfile还包含有关所需环境的有用信息。确保也提供无头配置,例如:
cypress run --headless --browser chrome --spec yourSpecHere.js
推荐阅读
- python - CTRL+C 不会终止 Windows 上 Python 3.6 脚本中的 aiohttp 应用程序
- python - Python Requests/BeautifulSoup 访问分页
- wordpress - Wordpress 图像大小问题
- php - 如何将数组中的字符串转换为数组并将两者结合在一起?
- reactjs - 如何在本机反应中从不同的组件修改组件的状态
- php - Laravel 404 的所有异常
- ruby-on-rails - CSV.foreach 适用于 txt 文件,但不适用于 CSV 文件
- winforms - 拖动无边框cef winform
- javascript - Browsersync:拒绝执行来自 'XX/app.js' 的脚本,因为它的 MIME 类型('text/html')不可执行等
- javascript - 使用 React 访问嵌套的 json