I have a scenario that I'm having difficulty with - in 2 separate environments I have 2 expected outcomes due to multi factor authentication. In one environment I have a popup notification that needs to be closed before other actions can take place. This is how I'm currently interacting with the button(no great locators):
cy.contains("Skip").click();
what I'd like to do is create a statement or condition that skips this click when the element isn't there. Everything I have tried up to this point has failed. Here is one example(I would assume I wouldn't get placed into the if here):
If statement HTML:
<p class="jss29">Enable Two Factor Authentication?</p>
if(cy.contains("Enable Two Factor Authentication?")){
cy.contains("Skip").click();
}else{
assert.ok("All Good");
}
Here is my error:
Timed out after retrying after 4000ms: Expected to find content: 'Skip' but never did.
cy.contains
immediately returns a truth-y value. You should read docs.cypress.io/guides/core-concepts/variables-and-aliases