Skip to content

Instantly share code, notes, and snippets.

Created February 14, 2016 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6f9ac6d2715169baa9bf to your computer and use it in GitHub Desktop.
Save anonymous/6f9ac6d2715169baa9bf 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