Skip to content

Instantly share code, notes, and snippets.

@dmolesUC
Last active July 10, 2018 20:18
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 dmolesUC/41130134a6ad3c00448b06503f397681 to your computer and use it in GitHub Desktop.
Save dmolesUC/41130134a6ad3c00448b06503f397681 to your computer and use it in GitHub Desktop.
Capybara: wait for Ajax with Prototype.js
# in spec/features_helper.rb
# adapted from https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
# for legacy Rails apps still using Prototype.js
def wait_for_ajax!
Timeout.timeout(Capybara.default_max_wait_time) do
# Error pages etc. may not have Ajax defined
loop until page.evaluate_script("(typeof Ajax === 'undefined') ? 0 : Ajax.activeRequestCount").zero?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment