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

123
Visualizações
How to check all links in cypress without stopping in case of an error

So basicly I have to test many many links on many many sites so I want to write a quite general code. In this case its just checking in the main section on purpose.

it('check all links in main', () => {

    cy.visit('/')
    cy.get("main").within(() => {
        cy.get("a").each(page => {
            cy.request(page.prop('href'))
        })
    })
});

This is checking all links but only as long as there are no errors. I want it to run through the whole page and just log out for every link if it works or not. Its not supposed to stop after the first error.

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

0

It looks like you are looking for the failOnStatusCode option

cy.get("a").each(page => {
  const link = page.prop('href')
  cy.request({
    url: link,
    failOnStatusCode: false  // allow good and bad response to pass into then
  }).then(response => {
    Cypress.log({
      name: link,
      message: response.status
    })
  })
})
about 4 years ago · Juan Pablo Isaza Relatório

0

Try putting your request in a .then()instance.

it('check all links in main', () => {

    cy.visit('/')
    cy.get("main").within(() => {
        cy.get("a").each(a => {
           cy.get(a).then((page) => {
           cy.request(page.prop('href'), {failOnStatusCode: false})
           cy.request({url: page.prop('href'), failOnStatusCode:false, })
           })
        })
    })
})
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