All my tests are running and passing as expected locally; however, there is one test that is failing when running on GitHub actions. The error I'm getting is:
CypressError: Timed out retrying after 60000ms:
`cy.wait()` timed out waiting `60000ms` for the 1st request to the route:
`addCustomerMutation`. No request ever occurred.
My code looks like this:
// IMPORTS
cy.intercept('POST', URL, (req) => {
delete req.headers['if-none-match'];
const addCustomerOp = 'addCustomerMutation';
const { body } = req;
if (body.hasOwnProperty('operationName' && body.operationName === addCustomerOp) {
req.alias = addCustomerOp;
req.reply({ data: addCustomer });
}
});
// FILL UP A FORM
cy.get('[data-testid="customer-save-button"]').click();
cy.wait('@addCustomerMutation', { timeout: 60000 })
.its('request.body.variables')
.should('deep.equal', {
clientId: 'client_id',
customer: {
firstName: 'test',
lastName: 'tester',
email: 'test@test.com',
phone: {
name: '',
number: '(531) 731-3151',
},
alternatePhones: [],
},
});
How can I resolve this issue? So far I tried:
- reverting cypress back to 6.4 and 6.8 per: https://github.com/cypress-io/cypress/issues/3427#issuecomment-462490501
- added another assertion right after wait per: https://stackoverflow.com/a/71754497/9842672
- increased timeout up to 100000
None of them worked. However, the local tests ran and passes with all these options as well.
My GitHub Actions workflow look like this if it helps:
jobs:
test:
concurrency: test # so that we don't run tests for another branch at the same time
runs-on: ubuntu-latest
container: cypress/browsers
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup npm token
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_RO }}" >> ./.npmrc
- name: Setup node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
cache: npm
- name: Npm install
run: npm ci
- name: Run tests
uses: cypress-io/github-action@v5
with:
env: username=${{ secrets.CYPRESS_TEST_USER }},password=${{ secrets.CYPRESS_TEST_PASSWORD }},REACT_APP_URI=${{ secrets.REACT_APP_URI }}
install-command: | # TODO: check node modules before you npm ci here
npm ci --production=false
browser: chrome
spec: cypress/integration/*.spec.*
start: npm run start:cypress
wait-on: npx wait-on http://localhost:3000
- name: Upload test screenshots
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
# Test run video was always captured, so this action uses "always()" condition
- name: Upload test videos
uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-videos
path: cypress/videos