问题
我正在为 Cypress 运行集成测试,该测试在本地运行良好,但在 Gitlab 中运行时失败。我收到的错误是在使用 cy.visit()
时导致以下错误的命令:
CypressError: `cy.visit()` failed trying to load:
http://localhost:3000/ The response we received from your web server
was:
404: Not Found
配置我使用以下命令启动测试:
tests:
image: cypress/base:10
stage: tests
script:
- npm ci
- npm run test:ci
我的 package.json
中的命令如下所示: "scripts": {
"start:ci": "serve dist --no-clipboard --listen ${PORT:-3000}",
"test": "cross-env NODE_ENV=test && npm run test:jest && npm
run test:cypress",
"test:ci": "start-server-and-test start:ci http://localhost:3000 test",
"test:cypress": "cypress run --headless",
"test:jest": "jest",
},
研究 我查看了错误,发现 this线程帮助我稍微理解了这个问题。然后我尝试将以下配置添加到我的
cypress.json
文件:{
"baseUrl": "http://localhost:3000"
}
但我仍然得到同样的错误。为什么会这样?
最佳答案
在 url 的末尾添加一个斜线,或者如果您可以在发出请求时删除斜线。
关于javascript - Cypress - cy.visit() 尝试加载失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69730790/