我刚刚开始尝试 Cypress 测试框架。我在 Jenkins 作业中运行了一个简单的测试,该测试是由安装和启动服务器的上游作业启动的。它还通过在新启动的服务器上点击 URL 来运行一些单元测试,因此必须启动服务器才能成功完成并启动 cypress 测试作业。
由于某种原因,cypress 间歇性失败,因为它无法验证基本 URL 上的服务器是否正在运行。我删除了基本 url 配置,并在 cy.visit() 中使用完整的 url,到目前为止它已成功运行。
有人知道为什么 Cypress 验证基本 URL 时会间歇性失败吗?
这是我用来运行测试的代码。我正在运行 Gulp 任务:
gulp.task('run-ui-tests', function() {
return cypress.run({
spec: './cypress/integration/main_navigation.js',
config: {
//baseUrl: config.urlProtocol + "://" + config.e2eTestsBaseUrl,
viewportWidth: 1200,
viewportHeight: 660,
videoRecording: false,
toConsole: false
},
reporter: "junit",
reporterOptions: {
mochaFile: "cypress/results/test-output.xml",
toConsole: false,
rootSuiteTitle: "UI Test Suite",
testsuitesTitle: "UI Tests"
}
})
.then((results) => {
if (results.failures === 0) {
console.log(results.passes + " of " + results.tests + " tests passed!")
console.log(results.failures + " tests failed!")
console.log("Ran for " + results.duration);
} else {
throw new Error(results.failures + " UI tests failed!! See /cypress/results/test-output.xml for more details.");
}
})
.catch((err) => {
throw new Error(err)
});
});
最佳答案
事实证明,我尝试运行测试的开发服务器没有 DNS 条目。我输入了该内容,从那时起它就一直完美地工作。
关于node.js - Cypress 间歇性无法验证基本 url 是否正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49062282/