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

136
Visualizações
Cypress: How to get response of fourth request from alias?

I have an interceptor that is getting a GET request for an endpoint that happens four times.

cy.intercept(`endpoint/data*`).as(
      'texasCounties'
);

This happens four times seen here. enter image description here

The only important one for me in the last request, however, when I wait for the response it only pegs the first one and I can't access the response body of the fourth request. Here is what I have so far

cy.wait('@texasCounties').then((interceptor) => {
       const res = interceptor.response.body
       cy.log(res) //only print object for the first request but I need the fourth
})

I've tried cy.wait('@texasCounties').eq(3) to get the fourth request but this does not work.

Does anyone know how to do this?

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

0

If you only want need the last call, you can move your intercept just before the call is made.

With your attempt, you were close to the answer. You'll have to use .get('@alias') to get all intercepted requests and access the last one using .its(). This is what it will look like.

// intercept and other test code

cy.get('@texasCounties.all') // this will get all four intercepted requests
  .then(console.log) // if you want to log
  .should('have.length', 4) // you can make assertions 
  .its(3) // to access the fourth request
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