https://cypress.io logo
Hey team! Searching for advice. We use cypress for...
# e2e-testing
g
Hey team! Searching for advice. We use cypress for E2E testing and sometimes tests fail because of something didn't act as it should like a button didn't appear etc. However, after quick troubleshooting, we can see that it's related to network request failures(502 or timeout). The problem I can see now is it's not visible immediately that the request failed which makes an impression or a "flaky" test. What I'd like to do is to intercept all network requests and define an expectation for status code, I was able to do this with this code: cy.intercept(/.*host\/api\/.*/, request => { request.responseTimeout = 350; request.on('response', function (response) { expect(response.statusCode).is.lessThan(402, "For "+ request.url + " "); // Test will fail if an 4xx and 5xx errors happen }); }); Even so I can define response timeout I don't know how to assert when timeout run out. Any idea? Thanks in advance.