BigW Consortium Gitlab

wait_for_ajax.rb 448 Bytes
Newer Older
1 2
module WaitForAjax
  def wait_for_ajax
3
    Timeout.timeout(Capybara.default_max_wait_time) do
4 5 6 7 8
      loop until finished_all_ajax_requests?
    end
  end

  def finished_all_ajax_requests?
9
    return true unless javascript_test?
10
    return true if page.evaluate_script('typeof jQuery === "undefined"')
11

12 13
    page.evaluate_script('jQuery.active').zero?
  end
14 15

  def javascript_test?
16
    Capybara.current_driver == Capybara.javascript_driver
17
  end
18
end