检查水豚中多个文本节点内容时的计时问题
我们在页面上有一个快速搜索字段,它通过 AJAX 调用过滤先前搜索的结果列表。
我们尝试了多种方法来检查更改列表的内容。
一开始,有一个像这样的列表:
<div class="search-list">
<div class="entry">
<div class="job-title">Manager</div>
...
</div>
<div class="entry">
<div class="job-title">Slave</div>
...
</div>
</div>
快速搜索后,整个搜索 search-list
将被 AJAX 响应替换,第二个 entry
div 为已删除。
我们尝试使用以下语句检查此条件:
page.find('.search-list .job-title').map(&:text) =~ ['Manager']
但它只能看到发出 AJAX 请求之前的状态。这可能是由于立即检查条件而没有等待 AJAX 请求完成。我们尝试了多种方法,例如设置 Selenium 驱动程序的 resynchronize
选项。
将 sleep 10 放在上面的行前面确实有效,但这是一个不干净的解决方案。目前我们不知道如何让它发挥作用,其他人知道吗?
We're having a quick search field on a page which filters the result list of a previous search via an AJAX call.
We have tried several methods of checking the content of the changed list.
At the beginning, there is a list like e.g. this:
<div class="search-list">
<div class="entry">
<div class="job-title">Manager</div>
...
</div>
<div class="entry">
<div class="job-title">Slave</div>
...
</div>
</div>
After the quick search, the whole search search-list
will be replaced by an AJAX response with the second entry
div being removed.
We're trying to check this condition with the following statement:
page.find('.search-list .job-title').map(&:text) =~ ['Manager']
but it only sees the state before the AJAX request has been made. This is probably due to the condition being checked immediately without waiting for the completion of the AJAX request. We have tried several methods, like settings the Selenium driver's resynchronize
option.
Putting a sleep 10 in front of the above line does work, but is an unclean solution. Currently we have no idea how to get this working, does anyone else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用
wait_until
的辅助方法来等待 ajax 完成,然后进行测试。所以也许像这样:
wait_until
等待块返回true
(尽管它会在一段时间后超时)。您还可以向其传递一个超时值wait_until(5)
,以便在分配的时间后退出。您还可以延长水豚的等待时间。
Angular.js
angular.element.active == 0
的更新以同样的方式工作。jQuery.active == 0
仍然可以在 Angular.js 中工作,但不确定这是否是因为我将 jQuery 作为我的 javascript 库的一部分。I use a helper method using
wait_until
to wait for the ajax to finish, then do my test.So perhaps something like:
wait_until
wait untiltrue
is returned by the block (though it will timeout after a little bit). You can also pass it a timeout value,wait_until(5)
, to exit after the time allotted.You could also possibly up your Capybara wait time.
Update for Angular.js
angular.element.active == 0
works in the same fashion.jQuery.active == 0
stil works within Angular.js, but not sure if that is because I have jQuery as part of my javascript libraries.