cypress expect element to be one thing or another

Viewed 108

I have two states on a website I am testing, either the element is set to .Image or .image so I need to validate that either one is present.

cy.get(".Image").should('exist')

but of course I need to extend this so it also looks for .image

Thanks,

3 Answers

You can use comma and then write both the selectors. This will act as a OR condition.

cy.get('.Image,.image').should('exist')

Cypress does not care (in this scenario).

cy.get(".Image").should('exist') will pick up both spans in

<span class="Image"></span>
<span class="image"></span>

Contains method with regex should do the job:

cy.contains('/^\.\b(Image)\b/i').should('exist')
Related