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

128
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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