Skip to content

Instantly share code, notes, and snippets.

@shivabhusal
Forked from anonymous/wait_for_ajax.rb
Created February 14, 2016 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivabhusal/922597687f52f911b2d4 to your computer and use it in GitHub Desktop.
Save shivabhusal/922597687f52f911b2d4 to your computer and use it in GitHub Desktop.
When there is ongoing Ajax Request during Capybara test session. You can make capybara wait till all the Ajax Requests finish first. - This Code chunk is actually provided by ThoughtBot - https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
# spec/support/wait_for_ajax.rb
# There is inbuild `wait_for_ajax` method in selinium WebDriver library
# This is for Capybara Webkit only
# #
module WaitForAjax
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop until finished_all_ajax_requests?
end
end
def finished_all_ajax_requests?
page.evaluate_script('jQuery.active').zero?
end
end
RSpec.configure do |config|
config.include WaitForAjax, type: :feature
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment