Capybara ajax race conditions

丶灬走出姿态 提交于 2019-12-04 17:07:34

I had issues with this a while back, and used this approach to figure out when the ajax requests are done:

wait_until do
  page.evaluate_script('$.active') == 0
end

Still pretty hacky, but slightly better than using sleep. I got it from here. I'm using it for Cucumber features but it should work in rspec request specs as well.

Update (6/19/2013)

wait_until was removed from Capybara in version 2.0, see: Why wait_until was removed from Capybara for details on why.

I've followed one of the suggestions and implemented it anyway, just for this one case (which I think is justified):

def wait_until
  require "timeout"
  Timeout.timeout(Capybara.default_wait_time) do
    sleep(0.1) until value = yield
    value
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!