Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

310
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda