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

Commit 7b96db0

Browse files
Will Jamessjelin
Will James
authored andcommitted
feat(browser.get): Return a promise that handles errors in browser.get
1 parent d70f152 commit 7b96db0

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

lib/protractor.js

+26-17
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement) {
212212
* when running element explorer.
213213
* @private {number}
214214
*/
215-
this.debuggerServerPort_;
215+
this.debuggerServerPort_;
216216
};
217217

218218
/**
@@ -448,11 +448,14 @@ Protractor.prototype.get = function(destination, opt_timeout) {
448448
return this.driver.get(destination);
449449
}
450450

451-
this.driver.get(this.resetUrl);
451+
var deferred = webdriver.promise.defer();
452+
453+
this.driver.get(this.resetUrl).then(null, deferred.reject);
452454
this.executeScript_(
453455
'window.name = "' + DEFER_LABEL + '" + window.name;' +
454456
'window.location.replace("' + destination + '");',
455-
msg('reset url'));
457+
msg('reset url'))
458+
.then(null, deferred.reject);
456459

457460
// We need to make sure the new url has loaded before
458461
// we try to execute any asynchronous scripts.
@@ -473,7 +476,8 @@ Protractor.prototype.get = function(destination, opt_timeout) {
473476
}
474477
});
475478
}, timeout,
476-
'waiting for page to load for ' + timeout + 'ms');
479+
'waiting for page to load for ' + timeout + 'ms')
480+
.then(null, deferred.reject);
477481

478482
// Make sure the page is an Angular page.
479483
self.executeAsyncScript_(clientSideScripts.testForAngular,
@@ -488,7 +492,8 @@ Protractor.prototype.get = function(destination, opt_timeout) {
488492
}
489493
}, function(err) {
490494
throw 'Error while running testForAngular: ' + err.message;
491-
});
495+
})
496+
.then(null, deferred.reject);
492497

493498
// At this point, Angular will pause for us until angular.resumeBootstrap
494499
// is called.
@@ -503,13 +508,17 @@ Protractor.prototype.get = function(destination, opt_timeout) {
503508
then(null, function(err) {
504509
throw 'Error while running module script ' + name +
505510
': ' + err.message;
506-
});
511+
})
512+
.then(null, deferred.reject);
507513
}
508514

509-
return this.executeScript_(
515+
this.executeScript_(
510516
'angular.resumeBootstrap(arguments[0]);',
511517
msg('resume bootstrap'),
512-
moduleNames);
518+
moduleNames)
519+
.then(deferred.fulfill, deferred.reject);
520+
521+
return deferred;
513522
};
514523

515524
/**
@@ -627,14 +636,14 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
627636
webdriver.promise.ControlFlow.prototype.getControlFlowText = function() {
628637
var controlFlowText = this.getSchedule(/* opt_includeStackTraces */ true);
629638
// This filters the entire control flow text, not just the stack trace, so
630-
// unless we maintain a good (i.e. non-generic) set of keywords in
631-
// STACK_SUBSTRINGS_TO_FILTER, we run the risk of filtering out non stack
632-
// trace. The alternative though, which is to reimplement
639+
// unless we maintain a good (i.e. non-generic) set of keywords in
640+
// STACK_SUBSTRINGS_TO_FILTER, we run the risk of filtering out non stack
641+
// trace. The alternative though, which is to reimplement
633642
// webdriver.promise.ControlFlow.prototype.getSchedule() here is much
634643
// hackier, and involves messing with the control flow's internals / private
635-
// variables.
644+
// variables.
636645
return helper.filterStackTrace(controlFlowText);
637-
646+
638647
};
639648

640649
if (opt_debugPort) {
@@ -677,7 +686,7 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
677686
});
678687
};
679688
var sandbox = vm_.createContext(context);
680-
689+
681690
var browserUnderDebug = this;
682691

683692
// Helper used only by debuggers at './debugger/modes/*.js' to insert code
@@ -734,11 +743,11 @@ Protractor.prototype.initDebugger_ = function(debuggerClientPath, opt_debugPort)
734743
return undefined;
735744
} else {
736745
// The '' forces res to be expanded into a string instead of just
737-
// '[Object]'. Then we remove the extra space caused by the '' using
738-
// substring.
746+
// '[Object]'. Then we remove the extra space caused by the '' using
747+
// substring.
739748
return util.format.apply(this, ['', res]).substring(1);
740749
}
741-
});
750+
});
742751
};
743752
this.execute_(execFn_);
744753
},

0 commit comments

Comments
 (0)