Capybara switch_to.alert(对话框)间歇性故障
我正在尝试使用 RSPEC / Capybara 与 FF 中的对话框进行交互。
在以下位置找到了一个优雅的解决方案:如何使用 Cucumber 测试确认对话框?< /a>
page.driver.browser.switch_to.alert.accept
然而,当切换没有发生时,我们会遇到间歇性故障。
有人遇到过这种情况吗?无论如何要确保切换始终成功?
谢谢!
I'm trying to interact with a dialog box in FF using RSPEC / Capybara.
Found a elegant solution in: How to test a confirm dialog with Cucumber?
page.driver.browser.switch_to.alert.accept
However we're getting intermittent failures when the switch doesn't happen.
Anyone encountered this? Anyway to ensure the switch is always successful?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如答案所述,当模式警报/确认/提示对话框打开时,浏览器将变得无响应。如今,即使浏览器已经学会了显示非模式窗口,Capybara 仍然无法评估页面上下文中的任何代码。
正如链接的答案所述,只需存根
window.confirm
方法即可。这是最好的稳定方式。您可以在 Capybara 中编写以下两个步骤:
然后您可以继续重写您的 Capybara 步骤,以便首先确保您对确认框进行存根,然后单击触发确认的链接盒子:
As the answer states, the Browser becomes unresponsive when the modal Alert/Confirm/Prompt dialog boxes open. Nowadays, even though browsers have learnt to show non-modal windows, Capybara still can't evaluate any code in the page context.
As the linked answer states, just stub the
window.confirm
method. That is the best stable way.You can write the following two steps in Capybara:
Then you can proceed to rewrite your Capybara steps, so that first you make sure you stub the confirm box, and then you click on the link that triggers the confirm box: