使用 Capybara 测试 javascript 警报

发布于 2024-08-31 01:20:35 字数 266 浏览 3 评论 0原文

我正在使用 Cucumber + capybara + selenium 来运行自动化测试,但我无法找到一种方法来断言显示 javascript 警报。

这个问题似乎有一个硒解决方案,但我不知道如何调用使用 Capybara 的 selenium 对象。

有没有一种简单的方法可以使用水豚测试警报?或者有解决方法吗?

I'm using Cucumber + capybara + selenium to run automated testing, but I'm having trouble finding a way to assert that a javascript alert is displayed.

This question seems has a solution with selenium, but I can't figure out how to call the selenium object using Capybara.

Is there a simple way to test for alerts using Capybara? Or is there a workaround?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

写下不归期 2024-09-07 01:20:35

我尝试过这样做,但水豚不支持。 Capybara 附带 Selenium 2.0,而不是 Selenium RC(如页面中所述),Selenium RC 是一个库,支持该方法。

在 Capybara 之外将其与 Cucumber 一起使用涉及加载和初始化 selenium 客户端驱动程序。我假设你在 Rails 的上下文中使用它,所以它需要设置环境,我不确定这需要多少工作,但我想说不值得这么麻烦。

如果您担心的是 link_to ... 创建的警报:confirm => “你确定吗?”类似地,不用担心,Cucumber 为那些使用一些伪 js 模拟的人提供了一个很好的解决方法。

I've tried to do it, but Capybara doesn't support it. Capybara comes with Selenium 2.0, not Selenium RC (as stated in the page), which is the library that supports that method.

Using it with Cucumber outside of Capybara involves loading and initializing the selenium-client driver. I assume you are using it within the context of Rails, so it will require setting up the environment, I'm not sure how much work is this, but I'd say is not worth the hassle.

If your concern are the alerts created by the link_to ... :confirm => "Are you sure?" and similar, don't worry, Cucumber provides a nice workaround for those with some pseudo-js emulation.

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