2015-12-23 02:04:40 +05:30
|
|
|
module WaitForAjax
|
|
|
|
def wait_for_ajax
|
2016-06-02 11:05:42 +05:30
|
|
|
Timeout.timeout(Capybara.default_max_wait_time) do
|
2015-12-23 02:04:40 +05:30
|
|
|
loop until finished_all_ajax_requests?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def finished_all_ajax_requests?
|
2017-08-17 22:00:37 +05:30
|
|
|
return true unless javascript_test?
|
|
|
|
return true if page.evaluate_script('typeof jQuery === "undefined"')
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
page.evaluate_script('jQuery.active').zero?
|
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
def javascript_test?
|
2017-08-17 22:00:37 +05:30
|
|
|
Capybara.current_driver == Capybara.javascript_driver
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|