We use Selenium WebDriver to automate our UI based tests. One of our challenges is to detect when a page is truly done loading, and Angular 1 was a challenge in that regard as well. We ended up executing this piece of code specifically to detect if Angular 1 is done:
if(typeof window.angular !== \"undefined\")
{
var injector = window.angular.element(\"*[ng-app]\").eq(0).injector();
if(injector)
{
var $rootScope = injector.get(\"$rootScope\");
var $http = injector.get(\"$http\");
if($rootScope.$$phase === \"$apply\" || $rootScope.$$phase === \"$digest\" || $http.pendingRequests.length !== 0)
{
return false;
}
}
}
The app that we are testing recently switched over to use Angular 2. The code snippet above does not wait for Angular 2 to finish. Any suggestions?
Using @alecxe answer i ended up with following javascript one liner to check if all Angular Testabilities are stable
window.getAllAngularTestabilities().findIndex(x=>!x.isStable()) === -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With