Does Capybara require sleep to work?

大城市里の小女人 提交于 2019-12-04 03:22:45

In case your not doing this already, in your test assertion if you check for the content on the page it will wait for a set amount of time until that content becomes available.

So, instead of adding a sleep you can add something like

expect(page).to have_content 'Success'

Capybara accommodates Ajax and loading of elements etc. so it will wait implicitly when checking content.

You can alter the default wait time if you need to allow for loading of elements which you know may take longer i.e. 3rd partying queries/logins

Capybara.default_wait_time = 5

A good alternative of wait_until and sleep is using_wait_time, an example of which is shown below.

using_wait_time 5 do
  page.should have_content '<content>'
end

You can also reload the page, after which you can check whatever conditions you have. This works for me at times.

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