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

127
Vistas
cypress - assert something and then assert it again

I'm trying to assert something on element 1 but i dont want cypress to display an error if the condition fails. instead, I want cypress to check something else and only if this second assertion fails I want cypress to throw a message.

//first assertion    
cy.get(`[data-cy="xxx"] > [data-cy="yyy"] > .x > .y`).should('have.css', 'color', 'rgb(227, 11, 11)');
//second assertion
cy.get(`element 2`).should('have.css', 'color', 'rgb(227, 11, 11)');
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can do a conditional check for this, something like this:

cy.get('[data-cy="xxx"] > [data-cy="yyy"] > .x > .y')
  .invoke('css', 'color')
  .then((cssColor) => {
    if (cssColor == 'rgb(227, 11, 11)') {
      cy.log('Expected color is present')
    } else {
      //this will throw error if failed
      cy.get('element 2').should('have.css', 'color', 'rgb(227, 11, 11)')
    }
  })
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can assert either one or the other element has the color value (since the condition is the same in both cases) by using a comma between the selectors

cy.get('[data-cy="xxx"] > [data-cy="yyy"] > .x > .y, element2')
  .should('have.css', 'color', 'rgb(227, 11, 11)')
about 4 years ago · Juan Pablo Isaza 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