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

Commit

Permalink
fix(pageload): add a wait during protractor.get() to solve unload issues
Browse files Browse the repository at this point in the history
Some systems would not wait for the browser unload event to finish
before beginning the asynchronous script execution.

Closes #406. Closes #85.
  • Loading branch information
juliemr committed Jan 23, 2014
1 parent 26dc1c6 commit a0bd84b
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ Protractor.prototype.clearMockModules = function() {
*/
Protractor.prototype.get = function(destination, opt_timeout) {
var timeout = opt_timeout || 10;
var self = this;

destination = url.resolve(this.baseUrl, destination);

if (this.ignoreSynchronization) {
Expand All @@ -562,7 +564,15 @@ Protractor.prototype.get = function(destination, opt_timeout) {
this.driver.get('about:blank');
this.driver.executeScript(
'window.name = "' + DEFER_LABEL + '" + window.name;' +
'window.location.href = "' + destination + '"');
'window.location.assign("' + destination + '");');

// At this point, we need to make sure the new url has loaded before
// we try to execute any asynchronous scripts.
this.driver.wait(function() {
return self.driver.getCurrentUrl().then(function(url) {
return url !== 'about:blank';
});
}, 300);

var assertAngularOnPage = function(arr) {
var hasAngular = arr[0];
Expand All @@ -574,24 +584,10 @@ Protractor.prototype.get = function(destination, opt_timeout) {
};

// Make sure the page is an Angular page.
var self = this;

self.driver.executeAsyncScript(clientSideScripts.testForAngular, timeout).
then(assertAngularOnPage, 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.
self.driver.executeAsyncScript(
clientSideScripts.testForAngular, timeout).
then(assertAngularOnPage, function(err) {
if (/reload detected during async script/.test(err.message)) {
throw 'Persistent async reload interrupt problem: ' + err.message;
} else {
throw 'Error while running testForAngular: ' + err.message;
}
});
} else {
throw 'Error while running testForAngular: ' + err.message;
}
throw 'Error while running testForAngular: ' + err.message;
});

// At this point, Angular will pause for us, until angular.resumeBootstrap
Expand Down

0 comments on commit a0bd84b

Please sign in to comment.