Created
January 19, 2015 10:31
-
-
Save divineforest/b55d64e9a018922043f0 to your computer and use it in GitHub Desktop.
Capybara wait for AJAX request finished
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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