[英]cy.intercept not working in Github pipeline
I've added cypress test to my project and it works perfectly fine on my local, both with cypress open
and cypress run
, headed and headless, chrome and electron.我已经在我的项目中添加了 cypress 测试,它在我的本地上运行良好,包括cypress open
和cypress run
、headed 和 headless、chrome 和 electron。
So moved on to add it to github workflow to run it on pipeline.因此继续将其添加到 github 工作流中以在管道上运行它。
Here's the Cypress Run
config in the ci.yml
file.这是ci.yml
文件中的Cypress Run
配置。
- name: Cypress Run
uses: cypress-io/github-action@v4
with:
install: false
browser: chrome
headed: true
working-directory: ./app
build: yarn build
start: yarn start
config-file: cypress.config.js
spec: ./cypress/tests/e2e/**/*.js
wait-on-timeout: 300
wait-on: 'http://localhost:3000, http://localhost:8001'
record: true
parallel: true
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
localhost:3000 is the app, localhost:8001 is the api. localhost:3000 是应用程序,localhost:8001 是 api。 I've confirmed that the app and api are running fine from recorded screenshots.我已经确认该应用程序和 api 从录制的屏幕截图中运行良好。
The thing is that intercept and wait are not working fine.问题是拦截和等待不能正常工作。 They're failing with timeout exceeded error.他们因超时超出错误而失败。
cy.intercept('POST', '/communications', req => {
req.reply({
statusCode: 200,
body: { data: {} }
})
}).as('addCallTodo')
cy.visit('/')
cy.get(cyTag(Tags.CALL_FORM.ADD_TODO_BUTTON))
.click()
cy.wait('@addCallTodo')
The error is here.错误就在这里。
CypressError: Timed out retrying after 5000ms: `cy.wait()` timed out waiting `5000ms` for the 1st request to the route: `addCallTodo`. No request ever occurred.
I've checked the cypress github issues but couldn't find a proper solution.我检查了 cypress github 问题,但找不到合适的解决方案。
I had the similar problem and one hacky solution was to add a dummy intercept at the beginning of the test.我遇到了类似的问题,一个 hacky 解决方案是在测试开始时添加一个虚拟拦截。
Something like就像是
cy.intercept('/dummy').as('dummy')
Usually github pipeline is using Unix environment and some actions like API calls could take longer than local environment.通常 github 管道使用 Unix 环境,像 API 调用这样的操作可能比本地环境花费更长的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.