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

317
Visualizações
Cypress Error Catching: how to catch error, warn using cy.log(), then continue with test

so I'm trying to use something like "error catching" to catch an error, cy.log a custom error message, then continue with the test without error catching after that point.

For example, clicking a button that increases quantity in cart, then asserting a change in the quantity #.

  • If the quantity # doesn't update within 2 seconds, warn in console.
  • If the quantity # doesn't update 6 seconds later (for 8 second global default timeout), fail test step
//some sort of error catching here which suppresses the error, and cy.logs 

cy.get("#AddToCart").click()
cy.get("#cart-count", timeout: 2000).should(contain, 2)

//disable error catching here

cy.get("#cart-count", timeout: 6000).should(contain, 2)

I tried something like

cy.on("error", (err, runnable) => {
          expect(err.message).to.include("blue");
          cy.log("this single test failed, but continue other tests");
          return false;
        });
        cy.get(".cy-prc")
          .should("be.visible")
          .invoke("text")
          .should("include", "blue");

Where the .should("include", "blue") should fail. If I can get this to fail and cy.log, then find a way to disable the error catch and do the 2nd assertion, I think I could get this working as I'm hoping it to.

Edit: We're trying to measure potential performance issues within a certain threshold, and have a custom warning printed to console when a threshold is exceeded without failing the test. We have several components or elements that can be affected by small changes in the backend, and we'd like to have warnings when we're approaching an unacceptable threshold before they become failing criteria.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There's a couple of command: events that might be useful

const commands = []

function commandStart(cmd) {
  const id = cmd.attributes.id
  commands.push({
    ...cmd.attributes,
    started: +new Date(),
  })
}

function commandEnd(cmd) {
  const entry = commands.filter(c => c.id === cmd.attributes.id)[0]
  entry.ended = +new Date()
  entry.duration = entry.ended - entry.started
}

Cypress.on('command:start', commandStart)
Cypress.on('command:end', commandEnd)

cy.get("#AddToCart").click()
cy.get("#cart-count", timeout: 2000).should(contain, 2)

The commands will look like

enter image description here

so to check the 2nd command

cy.then(() => {
  cy.wrap(commands[1])
    .its('duration')
    .should('be.lt', 6000)

  // turn off command duration
  Cypress.off('command:start', commandStart)
  Cypress.off('command:end', commandEnd)
})
about 4 years ago · Santiago Trujillo 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