2015-12-07 17:08:22 -05:00
|
|
|
module WaitForAjax
|
|
|
|
def wait_for_ajax
|
2016-03-15 14:03:17 -04:00
|
|
|
Timeout.timeout(Capybara.default_max_wait_time) do
|
2015-12-07 17:08:22 -05:00
|
|
|
loop until finished_all_ajax_requests?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def finished_all_ajax_requests?
|
2017-04-04 16:12:05 -04:00
|
|
|
return true unless javascript_test?
|
2017-04-19 18:55:02 -04:00
|
|
|
return true if page.evaluate_script('typeof jQuery === "undefined"')
|
2017-04-04 16:12:05 -04:00
|
|
|
|
2015-12-07 17:08:22 -05:00
|
|
|
page.evaluate_script('jQuery.active').zero?
|
|
|
|
end
|
2016-10-18 11:55:11 -04:00
|
|
|
|
|
|
|
def javascript_test?
|
2017-04-04 16:12:05 -04:00
|
|
|
Capybara.current_driver == Capybara.javascript_driver
|
2016-10-18 11:55:11 -04:00
|
|
|
end
|
2015-12-07 17:08:22 -05:00
|
|
|
end
|