Capybara/Selenium/Cucumber 未在文档就绪时运行 javascript

发布于 2024-10-29 06:25:25 字数 747 浏览 1 评论 0原文

我正在尝试使用 Cucumber 和 Capybara 为我的 Rails 应用程序编写一些集成测试。然而,我的应用程序的主页不会加载任何数据 - 一旦页面加载,它就会触发一个 javascript,检索数据以插入到页面中:

jQuery(document).ready(function() {
  pullUpdates();
});

pullUpdates 函数位于我的 application.js 中文件。

现在,诀窍是,如果我只是运行该应用程序,那么效果就很好。当我运行 Cucumber 时,它通过 selenium 在 Firefox 中打开页面,但数据从未加载。我首先尝试延长超时时间,所以现在它等待了整整三十秒才能加载数据 - 但它从来没有这样做。事实上,我已经进去查看了服务器日志,我的 javascript 似乎从未进行过 ajax 调用。

接下来,我找到了 capybara-firebug gem,认为也许我可以看看客户端的 javascript 中发生了什么 - 但当页面打开时它不会打开 firefox,因此它不会捕获任何这些javascript 错误排在第一位。我在firefox本身中打开了错误控制台,我认为有错误,但我无法读取它们,因为它们立即被selenium尝试检查它正在寻找的对象是否已经出现而吃掉。

我想这是一件简单、愚蠢的事情,也是我的错。但是,我不知道如何诊断它 - 它没有到达服务器,问题出在客户端的某个地方。我可以强制水豚在出错后保持页面打开,以便我可以返回并阅读错误日志吗?有没有更好的方法来解决这个问题?

I'm trying to write some integration tests for my Rails app using Cucumber, with Capybara. The main page of my application, however,d oes not load with any data in it - as soon as the page is loaded, it triggers a javascript that retrieves the data to insert into the page:

jQuery(document).ready(function() {
  pullUpdates();
});

The pullUpdates function lives in my application.js file.

Now, the trick is, if I simply run the application, this works fine. When I run cucumber, it opens the page in Firefox via selenium, but the data never loads. I tried extending the timeout first, so it waits a good thirty seconds now for the data to load - it never does. In fact, I've gone in and looked at the server log, and my javascript never seems to be even making the ajax call.

I found the capybara-firebug gem, next, thinking that perhaps I could just look and see what was happening in javascript on the client side - but it doesn't open firefox when the page opens, so it doesn't catch any of those javascript errors int he first place. I opened the Error console in firefox itself, nad I think htere is errors, but I cannot read them, because they are immediately eaten by selenium's attempts to check if the object it's looking for has shown up yet.

I imagine this is something simple, stupid, and my fault. But, I don't see how to diagnose it - its not hitting the server, the problem is on the client side somewhere. Can I force Capybara to leave the page open after it errors out, so that I can go back and read the error logs? Is there a better way to troubleshoot this?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文