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

Commit

Permalink
fix(clientsidescripts): workaround for IE 8 "async page reload" init …
Browse files Browse the repository at this point in the history
…problem
  • Loading branch information
David Simon authored and juliemr committed Nov 7, 2013
1 parent bac36d2 commit 81501c5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
10 changes: 7 additions & 3 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clientSideScripts.waitForAngular = function() {
angular.element(el).injector().get('$browser').
notifyWhenNoOutstandingRequests(callback);
} catch (e) {
callback(e.toString());
callback(e);
}
};

Expand Down Expand Up @@ -386,12 +386,16 @@ clientSideScripts.testForAngular = function() {
if (window.angular && window.angular.resumeBootstrap) {
callback([true, null]);
} else if (n < 1) {
callback([false, "timeout exceeded"]);
if (window.angular) {
callback([false, "angular never provided resumeBootstrap"]);
} else {
callback([false, "timeout exceeded"]);
}
} else {
window.setTimeout(function() {check(n - 1)}, 1000);
}
} catch (e) {
callback([false, e.toString()]);
callback([false, e]);
}
};
check(attempts);
Expand Down
37 changes: 29 additions & 8 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,21 +483,42 @@ Protractor.prototype.get = function(destination, timeout) {
'window.name = "' + DEFER_LABEL + '" + window.name;' +
'window.location.href = "' + destination + '"');

var angularTestHandler = function(arr) {
var hasAngular = arr[0];
if (!hasAngular) {
var message = arr[1];
throw new Error('Angular could not be found on the page ' +
destination + " : " + message);
}
};

// Make sure the page is an Angular page.
this.driver.executeAsyncScript(clientSideScripts.testForAngular, timeout).
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 + " : " + message);
var me = this;
me.driver.executeAsyncScript(clientSideScripts.testForAngular, timeout).
then(angularTestHandler, function(err) {
if (/reload detected during async script/.test(err.message)) {
// Sometimes IE will fail to run scripts right after a location change
// Let's try it once more
me.driver.executeAsyncScript(clientSideScripts.testForAngular, timeout).
then(angularTestHandler, function(err) {
if (/reload detected during async script/.test(err.message)) {
throw "Persistent async reload interrupt problem: " + err.message;
} else {
throw "While running testForAngular: " + err.message;
}
});
} else {
throw "While running testForAngular: " + err.message;
}
});

// At this point, Angular will pause for us, until angular.resumeBootstrap
// is called.
for (var i = 0; i < this.moduleScripts_.length; ++i) {
this.driver.executeScript(this.moduleScripts_[i]);
this.driver.executeScript(this.moduleScripts_[i]).
then(null, function(err) {
throw "While running module script: " + err.message;
});
}

return this.driver.executeScript(function() {
Expand Down

0 comments on commit 81501c5

Please sign in to comment.