-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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