adventurous-postman-3917
06/15/2022, 7:21 AMwindow:confirm to false using a callback function. I mean:
it('2-2 Alerts - Confirm - Dismiss', function () {
cy.visit('https://the-internet.herokuapp.com/javascript_alerts')
cy.contains('Click for JS Confirm').click()
cy.on('window:confirm', function (message) {
expect (message).eq('I am a JS Confirm')
return false
})
cy.get("#result").should('have.text', 'You clicked: Cancel')
cy.get("#result").invoke('text').should('equal', 'You clicked: Cancel')
});
If you want to know how to handle other types of Alerts, take a look at this file in my repo (related to my cypress YT course):
https://github.com/mmonfared/automationcamp-cypress/blob/master/cypress/e2e/session6.cy.js