3

I want to make an assertion in Cypress as follows:

cy.get(a).should('be.visible').or(()=>{
    cy.get(b).should('be.visible');
});

In other words, I want to check if condition A or condition B is true. How to do this in Cypress?

Fody
  • 23,754
  • 3
  • 20
  • 37
Hesham Moneer
  • 240
  • 1
  • 17

1 Answers1

4

One way is to use the jQuery multiple selector. It will require moving the visible assertion inside the the selector using :visible.

cy.get('a:visible, b:visible')

Be aware you sacrifice some of Cypress' built-in retry (as with all conditional testing).

For example, if b:visible now but a:visible in 1 second, it will give you b. Whereas cy.get(a).should('be.visible') will wait the second and return a.

Depending on details of the scenario, there are other ways.

Fody
  • 23,754
  • 3
  • 20
  • 37