问题
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