I just got this type of Alert and have no idea how to handle it with Cypress
Basically, I thought that from the documentation, cypress will automatically accept the alert but turned out the cypress window is stuck when alert appeared
I have tried with some solutions that I read online but none of them help. Like this one below
cy.on('window:confirm', str => {
expect(str).to.eq('do you swear you are a legitimate user and intend to act honestly?')
})
as they said that if this one return true or doesn't return any thing, it would work. But in real situation, it is not.
it('interceptorTrigger', () => {
cy.visit('http://localhost:9009/?path=/story/loginwithemail--interceptortrigger')
cy.getIframe('#storybook-preview-iframe')
.find('button')
.click()
cy.on('window:confirm', str => {
// expect(str).to.eq('do you swear you are a legitimate user and intend to act honestly?')
})
cy.wait(2000)
cy.log('done')
})
Try defining your cy.on('window:confirm',...)
BEFORE you call click()
Check out the "Catalog of Events" API documentation page if you scroll down to the Examples > Window Confirm it shows how to intercept the call and make assertions on it:
// Define
cy.on('window:confirm', (str) => {
expect(str).to.eq('first confirm')
// return false to deny
})
// THEN click
cy.get('button').click()
ALSO, mind sharing what your getIframe()
function looks like?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With