让水豚等到Ajax完成

让水豚等到Ajax完成

本文介绍了让水豚等到Ajax完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能测试,在页面上列出了待办事项列表,然后单击第一个待办事项以查看该待办事项的详细信息.第一个待办事项链接的ID为todo_1.

I have a feature test, where a list of todos are listed on a page and you click on first todo to see the details of that todo. The first todo link has ID todo_1.

我面临的问题是,在访问链接之前,我不知道如何等待链接出现.使用AJAX调用将待办事项列在表中.

The issue I'm facing is that I don't know how to wait for the link to appear before I visit it. The todos are listed in a table using an AJAX call.

推荐答案

Capybara在其大多数查找器和操作中都内置了等待行为,因此您通常不必专门等待ajax完成,因为Capybara等待页面上发生的可见变化.所以如果你这样做

Capybara has waiting behavior built in to most of its finders and actions, so you normally don't have to wait specifically for the ajax to finish since Capybara waits for the visible change on the page to occur. So if you do

visit 'page path'
find('selector to the todo div that gets clicked first').click
click_link 'todo_1'

click_link将最多等待Capybara.default_max_wait_time秒以显示链接.如果在测试中还不够长,则可以增加Capybara.default_max_wait_time或将等待选项传递给需要更长潜在等待时间的特定方法调用

The click_link will wait up to Capybara.default_max_wait_time seconds for the link to appear. If thats not long enough in your test you can either increase Capybara.default_max_wait_time or pass a wait option to the specific method call that needs a longer potential wait time

click_link 'todo_1', wait: 10

如果我不完全了解您在做什么,请发布更多的html使其更清晰

If I'm not understanding exactly what you're doing please post more of the html to make it clearer

这篇关于让水豚等到Ajax完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 23:27