如何避免 onbeforeunload 阻止 Watir 测试退出

发布于 2024-08-11 21:39:43 字数 419 浏览 2 评论 0原文

我有一个网页,每当用户尝试离开该页面时,它都会使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人接听 2024-08-18 21:39:43

如果您确实不需要测试该对话框,则可以覆盖 onbeforeunload。

不确定如何在 Watir 中完成,但在 Watir-WebDriver 中它看起来像

browser.execute_script "window.onbeforeunload = null"

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

browser.execute_script "window.onbeforeunload = null"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文