Skip to content

Instantly share code, notes, and snippets.

@tomeara
Created January 21, 2014 16:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomeara/8542986 to your computer and use it in GitHub Desktop.
Save tomeara/8542986 to your computer and use it in GitHub Desktop.
Reusing the main components of https://github.com/wrozka/capybara-angular, but made to be a "drop-in" module. Just use `wait_until_ready` whenever you want Capybara to catch-up to any Angular requests.
module AngularWaiter
def setup_ready
page.execute_script <<-JS
window.angularReady = false;
var app = $('*[ng-app]');
var injector = app.injector();
injector.invoke(function($browser) {
$browser.notifyWhenNoOutstandingRequests(function() {
window.angularReady = true;
});
});
JS
end
def ready?
page.evaluate_script("window.angularReady")
end
def wait_until_ready
setup_ready
until ready?
sleep(0.01)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment