Make capybara wait until Ajax finishes

只愿长相守 提交于 2021-01-07 08:23:09

问题


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.

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.


回答1:


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'

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

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



来源:https://stackoverflow.com/questions/33072556/make-capybara-wait-until-ajax-finishes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!