我正在使用 Cypress.io(版本 5.1.0)来测试我的项目。 我的项目位于 azure DevOps 中。现在我想将我的 cypress 测试包含在 Azure DevOps 中,这样我的测试就会自动运行。
我在我的 Cypress 项目中设置了 JUnit 报告器: 到我添加的“package.json”文件中
"cypress-multi-reporters": "^1.2.4",
"mocha-junit-reporter": "^1.23.3"
然后运行 npm 安装
比添加
"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
并编写命令 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://learn.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'
我收到一封包含此详细信息的电子邮件
Job 1 error(s), 1 warning(s) Error: Npm failed with return code: 254
最佳答案
该问题可能是由代理引起的,而不是由您的代码和脚本引起的。
您可以尝试以下解决方案:
更改您的代理形象。由于您当前使用的是
ubuntu-latest
,建议尝试ubuntu-20.04
或ubuntu-16.04
。使用自托管代理。如果您没有自托管代理,请单击Self-hosted Linux agent了解详细步骤。
更改组织。选择另一个可以正确运行构建的组织,为了以防万一,最好创建一个新组织。然后创建一个新项目并尝试测试。
关于azure - 为什么 Cypress 和 Azure DevOps 的测试自动化仅取得部分成功?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63794584/