I looking for a way to intercept all request in cypress. I'm thinking about a thing like that:
beforeEach(() => {
cy.intercept({method: 'GET', path: '*'}).as('get')
cy.intercept({method: 'POST', path: '*'}).as('post')
})
then:
afterEcah(() => {
cy.wait('@get').its('response.statusCode').should('be.oneOf', [200, 304])
cy.wait('@post').its('response.statusCode').should('be.oneOf', [200, 304, 201])
})
My problem is sometime in my test i don't have a get or a post request, so my test fail.
Maybe i need a condition is my afterEach()
but i can' t figure it out.
Or perhaps the problem is using afterEach()
for this purpose.
Any help will be welcome