Last active
December 16, 2015 13:29
-
-
Save the-teacher/5441852 to your computer and use it in GitHub Desktop.
Capybara 2.0 Wait for ajax
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
require "timeout" | |
module WaitForAjax | |
def self.delay | |
@delay || 1 | |
end | |
def self.delay= val | |
@delay = val | |
end | |
def self.max_time | |
@max_time || 10 | |
end | |
def self.max_time= val | |
@max_time = val | |
end | |
def wait_for_ajax &block | |
begin | |
Timeout.timeout(WaitForAjax.max_time) do | |
sleep(WaitForAjax.delay) and print '.' until value = yield | |
print "\n" | |
value | |
end | |
rescue TimeoutError | |
false | |
end | |
end | |
end | |
# WaitForAjax.max_time = 20 | |
# WaitForAjax.delay = 0.5 | |
# wait_for_ajax{ [true, false, false, false, false, false, false, false, false].sample } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment