cy.intercept not working in Github pipeline

Viewed 48

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.

So moved on to add it to github workflow to run it on pipeline.
Here's the Cypress Run config in the ci.yml file.

      - 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. I've confirmed that the app and api are running fine from recorded screenshots.

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.

1 Answers

I had the similar problem and one hacky solution was to add a dummy intercept at the beginning of the test.

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.

Related