While browsing the website an email popup alert may appear , how can I close it whenever it appears (the problem I don't know when it may appear)
if (cy.get('.popup').isDisplayed) {
cy.get('.popup a').click() // Close button
}
While browsing the website an email popup alert may appear , how can I close it whenever it appears (the problem I don't know when it may appear)
if (cy.get('.popup').isDisplayed) {
cy.get('.popup a').click() // Close button
}
To close whenever requires some sort of watcher, which doesn't quite fit the Cypress pattern.
Best approach would be to cy.stub() it so it never occurs. What type of popup do you have, what triggers it?
If it's timer based, you might be able to cy.clock() to freeze the clock. If you need to cy.tick(milliseconds) during the test, then follow it immediately with
if (Cypress.$('.popup').length) { // non-failing check if popup is present
cy.get('.popup a').click()
}