0

I'm trying to test a cookie consent banner with Cypress and route2. I have to use route2 because I have to test several types of network requests.

In my first scenario I want to make sure that, after accepting the consent, a request to Google Analytics is called.

Example:

cy.route2('https://www.google-analytics.com/gtm/js').as("getGA")
cy.visit("/")
cy.contains("button", "Accept", { timeout: 15000 }).click()
cy.wait('@getGA').its('response.statusCode').should('eq', 200)

In my second scenario I want to test that no request to Google Analytics is called before accepting the cookie consent.

I only found examples with cy.route() (for example here and here) but none with route2. Is this possible with route2?

  • May be cy.wait('@getGA').wait(4000).should('not.exist') – Rosen Mihaylov Nov 10 '20 at 09:21
  • Thanks for the response, but unfortunately this did not work: "Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: getGA. No request ever occurred." – Hello World Nov 19 '20 at 11:22
  • For the purpose of counting slow API response, I`ve been told by my seniors to put globalVariables: "defaultCommandTimeout": 60000, "requestTimeout": 60000, "responseTimeout": 60000, – Rosen Mihaylov Nov 19 '20 at 11:34

0 Answers0