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

Commit 36e0e0a

Browse files
committed
fix(protractor): allow exceptions from actions to be catchable
See #959
1 parent 89a1498 commit 36e0e0a

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

Diff for: lib/protractor.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,14 @@ var buildElementHelper = function(ptor) {
110110
return parentWebElement.findElements(this.locator_);
111111
}
112112
} else {
113-
ptor.waitForAngular();
114-
if (this.locator_.findElementsOverride) {
115-
return this.locator_.findElementsOverride(ptor.driver);
116-
} else {
117-
return ptor.driver.findElements(this.locator_);
118-
}
113+
var self = this;
114+
return ptor.waitForAngular().then(function() {
115+
if (self.locator_.findElementsOverride) {
116+
return self.locator_.findElementsOverride(ptor.driver);
117+
} else {
118+
return ptor.driver.findElements(self.locator_);
119+
}
120+
});
119121
}
120122
};
121123

@@ -470,8 +472,13 @@ var buildElementHelper = function(ptor) {
470472
WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
471473
if(!self[fnName]) {
472474
self[fnName] = function() {
473-
var webElem = self.getWebElement();
474-
var actionResult = webElem[fnName].apply(webElem, arguments);
475+
var args = arguments;
476+
var webElem = self.getWebElement();
477+
var actionResult = webElem.then(
478+
function(webElem_) {
479+
return webElem_[fnName].apply(webElem_, args);
480+
});
481+
475482
return new ElementFinder(
476483
locator, opt_parentElementFinder,
477484
actionResult, opt_index);
@@ -722,11 +729,9 @@ var buildElementHelper = function(ptor) {
722729
* @return {webdriver.promise.Promise} Promise which contains the results of
723730
* evaluating fn.
724731
*/
725-
ElementFinder.prototype.then = function(fn) {
732+
ElementFinder.prototype.then = function(fn, errorFn) {
726733
if (this.opt_actionResult_) {
727-
return this.opt_actionResult_.then(function() {
728-
return fn.apply(null, arguments);
729-
});
734+
return this.opt_actionResult_.then(fn, errorFn);
730735
} else {
731736
return fn(this);
732737
}

Diff for: spec/basic/elements_spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ describe('ElementFinder', function() {
292292
expect(element(byCss).locator()).toEqual(byCss);
293293
expect(element(byBinding).locator()).toEqual(byBinding);
294294
});
295+
296+
it('should propagate exceptions', function() {
297+
browser.get('index.html#/form');
298+
var successful = protractor.promise.defer();
299+
300+
var invalidElement = element(by.binding('INVALID'));
301+
invalidElement.getText().then(function(value) {
302+
successful.fulfill(true);
303+
}, function(err) {
304+
successful.fulfill(false);
305+
});
306+
expect(successful).toEqual(false);
307+
});
295308
});
296309

297310
describe('evaluating statements', function() {

0 commit comments

Comments
 (0)