如何避免 onbeforeunload 阻止 Watir 测试退出
我有一个网页,每当用户尝试离开该页面时,它都会使用 onbeforeunload 提示用户进行确认。当浏览器窗口关闭时,甚至会触发此确认。
我的问题是,此提示阻止 Watir 在测试运行结束时关闭 IE,至少直到我手动干预并单击“确定”为止。
我如何编写测试,以便即使测试失败,Watir 也会自动消除此提示?我认为测试拆卸方法中可能存在一些条件逻辑,但我需要与弹出窗口交互的帮助。
注意:我有一个不同的问题 与通过单击事件创建的 onbeforeunload 提示进行交互有关。这个问题是关于在关闭窗口的请求创建弹出窗口时处理该弹出窗口。
I have a webpage that uses onbeforeunload to prompt the user for confirmation whenever they try and navigate away from the page. This confirmation even fires when the browser window is closed.
My problem is that this prompt is preventing Watir from closing IE at the end of a test run, at least until I manually intervene and click "OK".
How can I write my tests such that Watir automatically dismisses this prompt, even if the test fails? I'm thinking there might be some conditional logic in the test teardown method, but I need help interacting with the popup.
Note: I have a different question pertaining to interacting with the onbeforeunload prompt when it is created by a click event. This question is about handling that popup when it is created by a request to close the window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确实不需要测试该对话框,则可以覆盖 onbeforeunload。
不确定如何在 Watir 中完成,但在 Watir-WebDriver 中它看起来像
If you don't really need to test that dialog, you can overwrite onbeforeunload.
Not sure how it can be done in Watir, but in Watir-WebDriver it'll look like