Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(clientsidescripts): better error reporting from testForAngular a…
Browse files Browse the repository at this point in the history
…nd waitForAngular
  • Loading branch information
David Simon authored and juliemr committed Nov 7, 2013
1 parent fb494a4 commit d383770
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
24 changes: 16 additions & 8 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ var clientSideScripts = exports;
clientSideScripts.waitForAngular = function() {
var el = document.querySelector(arguments[0]);
var callback = arguments[1];
angular.element(el).injector().get('$browser').
notifyWhenNoOutstandingRequests(callback);
try {
angular.element(el).injector().get('$browser').
notifyWhenNoOutstandingRequests(callback);
} catch (e) {
callback(e.toString());
}
};

/**
Expand Down Expand Up @@ -378,12 +382,16 @@ clientSideScripts.testForAngular = function() {
var attempts = arguments[0];
var callback = arguments[arguments.length - 1];
var check = function(n) {
if (window.angular && window.angular.resumeBootstrap) {
callback(true);
} else if (n < 1) {
callback(false);
} else {
window.setTimeout(function() {check(n - 1)}, 1000);
try {
if (window.angular && window.angular.resumeBootstrap) {
callback([true, null]);
} else if (n < 1) {
callback([false, "timeout exceeded"]);
} else {
window.setTimeout(function() {check(n - 1)}, 1000);
}
} catch (e) {
callback([false, e.toString()]);
}
};
check(attempts);
Expand Down
27 changes: 17 additions & 10 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,19 @@ Protractor.prototype.waitForAngular = function() {
return webdriver.promise.fulfilled();
}
return this.driver.executeAsyncScript(
clientSideScripts.waitForAngular, this.rootEl).then(null, function(err) {
if (!/asynchronous script timeout/.test(err.message)) {
throw err;
}
var timeout = /[\d\.]*\ seconds/.exec(err.message);
throw 'Timed out waiting for Protractor to synchronize with ' +
'the page after ' + timeout;
});
clientSideScripts.waitForAngular, this.rootEl).then(function(err) {
if (err) {
throw 'Error while waiting for Protractor to ' +
'sync with the page: ' + JSON.stringify(err);
}
}).then(null, function(err) {
if (!/asynchronous script timeout/.test(err.message)) {
throw err;
}
var timeout = /[\d\.]*\ seconds/.exec(err.message);
throw 'Timed out waiting for Protractor to synchronize with ' +
'the page after ' + timeout;
});
};

// TODO: activeelement also returns a WebElement.
Expand Down Expand Up @@ -477,10 +482,12 @@ Protractor.prototype.get = function(destination) {

// Make sure the page is an Angular page.
this.driver.executeAsyncScript(clientSideScripts.testForAngular, 10).
then(function(hasAngular) {
then(function(arr) {
var hasAngular = arr[0];
if (!hasAngular) {
var message = arr[1];
throw new Error('Angular could not be found on the page ' +
destination);
destination + " : " + message);
}
});

Expand Down

0 comments on commit d383770

Please sign in to comment.