So I'm trying to write some cypress code and the documentation imo isn't really clear.
I have two scenarios.
- A page is loaded with no loading spinner.
- A page is loaded with a loading spinner.
I would like to write code that would satisfy both scenarios and let the test just continue.
- If the page does not have a loading spinner element: Continue with the tests as usual.
- If the page does have a loading spinner element: Wait until the element disappears and then continue
Cypress has a lot of fancy functions but the documentation on how to use them just isn't clear enough.
I tried with the following piece of code:
try {
cy.getByTestId('loader-spinner')
.should('exist')
.then(el => {
el.should('not.exist');
});
} catch (error) {
cy.getByTestId('loader-spinner').should('not.exist');
}