Skip to content

Instantly share code, notes, and snippets.

@divineforest
Created January 19, 2015 10:31
Show Gist options
  • Save divineforest/b55d64e9a018922043f0 to your computer and use it in GitHub Desktop.
Save divineforest/b55d64e9a018922043f0 to your computer and use it in GitHub Desktop.
Capybara wait for AJAX request finished
def wait_for_ajax
return unless respond_to?(:evaluate_script)
wait_until { finished_all_ajax_requests? }
end
def finished_all_ajax_requests?
evaluate_script("!window.jQuery") || evaluate_script("jQuery.active").zero?
end
def wait_until(max_execution_time_in_seconds = Capybara.default_wait_time)
Timeout.timeout(max_execution_time_in_seconds) do
loop do
if yield
return true
else
sleep(0.05)
next
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment