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

Commit a0bd84b

Browse files
committed
fix(pageload): add a wait during protractor.get() to solve unload issues
Some systems would not wait for the browser unload event to finish before beginning the asynchronous script execution. Closes #406. Closes #85.
1 parent 26dc1c6 commit a0bd84b

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

lib/protractor.js

+13-17
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ Protractor.prototype.clearMockModules = function() {
553553
*/
554554
Protractor.prototype.get = function(destination, opt_timeout) {
555555
var timeout = opt_timeout || 10;
556+
var self = this;
557+
556558
destination = url.resolve(this.baseUrl, destination);
557559

558560
if (this.ignoreSynchronization) {
@@ -562,7 +564,15 @@ Protractor.prototype.get = function(destination, opt_timeout) {
562564
this.driver.get('about:blank');
563565
this.driver.executeScript(
564566
'window.name = "' + DEFER_LABEL + '" + window.name;' +
565-
'window.location.href = "' + destination + '"');
567+
'window.location.assign("' + destination + '");');
568+
569+
// At this point, we need to make sure the new url has loaded before
570+
// we try to execute any asynchronous scripts.
571+
this.driver.wait(function() {
572+
return self.driver.getCurrentUrl().then(function(url) {
573+
return url !== 'about:blank';
574+
});
575+
}, 300);
566576

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

576586
// Make sure the page is an Angular page.
577-
var self = this;
587+
578588
self.driver.executeAsyncScript(clientSideScripts.testForAngular, timeout).
579589
then(assertAngularOnPage, function(err) {
580-
if (/reload detected during async script/.test(err.message)) {
581-
// Sometimes IE will fail to run scripts right after a location change.
582-
// Let's try it once more.
583-
self.driver.executeAsyncScript(
584-
clientSideScripts.testForAngular, timeout).
585-
then(assertAngularOnPage, function(err) {
586-
if (/reload detected during async script/.test(err.message)) {
587-
throw 'Persistent async reload interrupt problem: ' + err.message;
588-
} else {
589-
throw 'Error while running testForAngular: ' + err.message;
590-
}
591-
});
592-
} else {
593-
throw 'Error while running testForAngular: ' + err.message;
594-
}
590+
throw 'Error while running testForAngular: ' + err.message;
595591
});
596592

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

0 commit comments

Comments
 (0)