且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

让水豚等到Ajax完成

更新时间:2023-11-20 23:45:31

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