cy.intercept, beforeEach, and inconsistent wait() #16842
Unanswered
bared-dave
asked this question in
CI setup
Replies: 1 comment 2 replies
-
context('NZD', () => {
beforeEach(() => {
cy.setLocalStorage('headless:subscribe', { value: 'hidden', expiry: 0 })
cy.intercept({ url: 'https://ipapi.co/json/?*', middleware: true }, mockLocationAPI('nz')).as('LocationNZ')
cy.intercept({ url: '**/api/*/graphql.json', middleware: true }, mockShopifyAPI)
cy.visit('/products/aluminium-black-lace-ups')
cy.wait(['@GetShopSettings', '@CheckoutCreate', '@GetProduct', '@LocationAU'])
}) Fixing the alias names fixes the tests for me |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I'm working on introducing Cypress tests into our codebase, and am having inconsistent results when trying to intercept API requests in beforeEach block, and inconsistent results in
visit()
waiting for pages to load.I've created a minimal repo which shows the problem. https://github.com/bared-dave/cypress-remote-url-test/
Sometimes this works locally, sometimes it doesn't. It almost never works in CI context. https://github.com/bared-dave/cypress-remote-url-test/actions
If we take this test as an example:
I have noticed that sometimes when
visit()
is called, the XHR requests that I'm attempting to intercept (and replace with a fixture) are called before thewait()
function is called, so then thewait()
function times out and the test fails because the XHR request has already been and gone.If I remove the
wait()
, sometimes the tests pass locally if the XHRs are intercepted before the individual tests are run, but most of the time they don't. I've been banging my head against the wall for 2 days trying to fix this.Is there a way to make these tests more consistent that I'm missing?
See below screenshot:
For reference we are using Gatsby, Gatsby cloud and Gitlab. I have setup Gatsby cloud webhook notification that calls a Gitlab webhook to trigger a job which runs the Cypress tests against a remote URL.
Beta Was this translation helpful? Give feedback.
All reactions