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

Commit d383770

Browse files
David Simonjuliemr
David Simon
authored andcommittedNov 7, 2013
feat(clientsidescripts): better error reporting from testForAngular and waitForAngular
1 parent fb494a4 commit d383770

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed
 

Diff for: ‎lib/clientsidescripts.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ var clientSideScripts = exports;
1818
clientSideScripts.waitForAngular = function() {
1919
var el = document.querySelector(arguments[0]);
2020
var callback = arguments[1];
21-
angular.element(el).injector().get('$browser').
22-
notifyWhenNoOutstandingRequests(callback);
21+
try {
22+
angular.element(el).injector().get('$browser').
23+
notifyWhenNoOutstandingRequests(callback);
24+
} catch (e) {
25+
callback(e.toString());
26+
}
2327
};
2428

2529
/**
@@ -378,12 +382,16 @@ clientSideScripts.testForAngular = function() {
378382
var attempts = arguments[0];
379383
var callback = arguments[arguments.length - 1];
380384
var check = function(n) {
381-
if (window.angular && window.angular.resumeBootstrap) {
382-
callback(true);
383-
} else if (n < 1) {
384-
callback(false);
385-
} else {
386-
window.setTimeout(function() {check(n - 1)}, 1000);
385+
try {
386+
if (window.angular && window.angular.resumeBootstrap) {
387+
callback([true, null]);
388+
} else if (n < 1) {
389+
callback([false, "timeout exceeded"]);
390+
} else {
391+
window.setTimeout(function() {check(n - 1)}, 1000);
392+
}
393+
} catch (e) {
394+
callback([false, e.toString()]);
387395
}
388396
};
389397
check(attempts);

Diff for: ‎lib/protractor.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,19 @@ Protractor.prototype.waitForAngular = function() {
245245
return webdriver.promise.fulfilled();
246246
}
247247
return this.driver.executeAsyncScript(
248-
clientSideScripts.waitForAngular, this.rootEl).then(null, function(err) {
249-
if (!/asynchronous script timeout/.test(err.message)) {
250-
throw err;
251-
}
252-
var timeout = /[\d\.]*\ seconds/.exec(err.message);
253-
throw 'Timed out waiting for Protractor to synchronize with ' +
254-
'the page after ' + timeout;
255-
});
248+
clientSideScripts.waitForAngular, this.rootEl).then(function(err) {
249+
if (err) {
250+
throw 'Error while waiting for Protractor to ' +
251+
'sync with the page: ' + JSON.stringify(err);
252+
}
253+
}).then(null, function(err) {
254+
if (!/asynchronous script timeout/.test(err.message)) {
255+
throw err;
256+
}
257+
var timeout = /[\d\.]*\ seconds/.exec(err.message);
258+
throw 'Timed out waiting for Protractor to synchronize with ' +
259+
'the page after ' + timeout;
260+
});
256261
};
257262

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

478483
// Make sure the page is an Angular page.
479484
this.driver.executeAsyncScript(clientSideScripts.testForAngular, 10).
480-
then(function(hasAngular) {
485+
then(function(arr) {
486+
var hasAngular = arr[0];
481487
if (!hasAngular) {
488+
var message = arr[1];
482489
throw new Error('Angular could not be found on the page ' +
483-
destination);
490+
destination + " : " + message);
484491
}
485492
});
486493

0 commit comments

Comments
 (0)