One option could be instead of overwriting the cy.visit()
command, you create a custom command with cy.visit(url)
and then the code to close the popup.
1.Go to cypress/support/commands.js
and write:
Cypress.Commands.add('openWebpage', () => {
cy.visit(url)
cy.get("body").then($body => {
if ($body.find("[text='Got it']").length > 0) {
cy.contains("Got it", {
matchCase: false
}).click();
}
})
})
2.In your tests you can just write:
cy.openWebpage()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…