Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!