From 81501c5d941cd7edb15439cef7c7a64c0e773e27 Mon Sep 17 00:00:00 2001 From: David Simon Date: Tue, 5 Nov 2013 16:07:37 -0500 Subject: [PATCH] fix(clientsidescripts): workaround for IE 8 "async page reload" init problem --- lib/clientsidescripts.js | 10 +++++++--- lib/protractor.js | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/clientsidescripts.js b/lib/clientsidescripts.js index 47147143a..bd679da1f 100644 --- a/lib/clientsidescripts.js +++ b/lib/clientsidescripts.js @@ -22,7 +22,7 @@ clientSideScripts.waitForAngular = function() { angular.element(el).injector().get('$browser'). notifyWhenNoOutstandingRequests(callback); } catch (e) { - callback(e.toString()); + callback(e); } }; @@ -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); diff --git a/lib/protractor.js b/lib/protractor.js index a3ebd0576..3e4a2a6d6 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -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() {