Created
January 21, 2014 16:11
-
-
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.
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
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