[英]Cypress handling alerts automatically
The web app I am testing gives an alert.我正在测试的 web 应用程序会发出警报。 I wanted to use cypress to test if the alert is being shown and click cancel on the alert but cypress is automatically confirming the alert.
我想使用 cypress 测试是否显示警报并单击警报上的取消,但 cypress 会自动确认警报。
Here is the code:这是代码:
cy.get('a').contains('Concepts').click();
cy.on('window:alert', (t) => {
//assertions
expect(t).to.contains('You have unsaved changes, are you sure you want to leave?');
return false;
})
I have returned false but still, on running the test, it says confirm without the assertion being handled and it goes to the new URL (which it should not).我返回了 false 但仍然在运行测试时,它说确认没有处理断言,它转到新的 URL(它不应该)。 (see image below)
(见下图)
What am I doing wrong?我究竟做错了什么?
Look like you are using window:confirm
not alert
.看起来您正在使用
window:confirm
not alert
。 Change it to confirm
instead改为
confirm
cy.on('window:confirm', (t) => {
//assertions
expect(t).to.contains('You have unsaved changes, are you sure you want to leave?');
return false;
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.