Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

351
Visualizações
Cypress: how to test routes status code throughout entire test?

I have a test where a certain fetch request is happening around 70 times and at the end of the test I need to check that all the status codes were 200 or 204. So far I am intercepting the request and can check the response.statusCode for that 1 request but I'm having trouble doing it for the rest. Here is what I have so far.

it('Testing', function () {
        cy.intercept('proxy/test*').as('test')
        cy.visit('/user/test');
        const aliases = [];
        for (let i = 1; i <= 70; i++){
            aliases.push('@test')
        }
        .............
        .............
        cy.wait(aliases).its('response.statusCode').should('eq', 200 || 204)

The error I am getting is

Timed out retrying after 4000ms: cy.its() errored because the property: response does not exist on your subject.

cy.its() waited for the specified property response to exist, but it never did.

Can anyone help with this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You said around 70 times, so if you test exactly 70 times and it's actually 69 you get a fail, even if all statusCodes are correct.

So you'll need a criteria that tells the test that fetches have stopped, usually something on the screen only appears after the final fetch.

Failing that, you can use a fixed wait, but generally you would try to avoid that.

Ref Intercepting-a-response

const statusCodes = []

cy.intercept('proxy/test*', (req) => {
  req.continue((res) => {
    statusCodes.push(res.statusCode)
  })
}).as('test')

// assert an element on page that only appears after all fetches finished

cy.wrap(statusCodes).should(codes => {
  expect(codes.every(code => code === 200 || code === 204)).to.eq(true)
})

If you do know the exact number of fetches, it's easier

const statusCodes = []

cy.intercept('proxy/test*', (req) => {
  req.continue((res) => {
    statusCodes.push(res.statusCode)
  })
}).as('test')

Cypress._.times(70, () => cy.wait('@test'))  // exact call count is known

cy.wrap(statusCodes).should(codes => {
  expect(codes.every(code => code === 200 || code === 204)).to.eq(true)
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda