简体   繁体   English

cy.intercept 在 Github 管道中不起作用

[英]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 opencypress 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.

相关问题 赛普拉斯 - cy.intercept 捕获错误 url - Cypress - cy.intercept catching wrong url 如何使用 cy.intercept() 使用不同的存根存根两个请求? - how to stub two requests with differents stubs using cy.intercept()? 如何清理 cypress cy.intercept 请求队列? - How to cleanup cypress cy.intercept requests queue? 如何在 Cypres.io 中使用 cy.intercept 操作任何路由和请求类型? - How to manipulate any route & request type with cy.intercept in Cypres.io? 赛普拉斯:使用 cy.intercept() 检查是否尚未进行调用? - Cypress: Using cy.intercept() to check if a call hasnt been made yet? 如何使用 cy.intercept 存根两个同名请求但返回两个不同的主体? - How can I use cy.intercept to stub two requests of the same name but return two different bodies? Github CD 管道因 codemirror 而崩溃 - Github CD pipeline crashes with codemirror Coffeescript在资产管道中不起作用 - Coffeescript not working in asset pipeline mongodb changestream“管道”不起作用 - mongodb changestream "pipeline" not working 一旦评估了一个真实值,谁能看到为什么我的 cy.waitUntil() 命令不起作用? - Can anyone see why my cy.waitUntil() command is not working, once evaluating a truthy value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM