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

Commit

Permalink
fix(protractor): allow exceptions from actions to be catchable
Browse files Browse the repository at this point in the history
See #959
  • Loading branch information
hankduan committed Jun 20, 2014
1 parent 89a1498 commit 36e0e0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
29 changes: 17 additions & 12 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ var buildElementHelper = function(ptor) {
return parentWebElement.findElements(this.locator_);
}
} else {
ptor.waitForAngular();
if (this.locator_.findElementsOverride) {
return this.locator_.findElementsOverride(ptor.driver);
} else {
return ptor.driver.findElements(this.locator_);
}
var self = this;
return ptor.waitForAngular().then(function() {
if (self.locator_.findElementsOverride) {
return self.locator_.findElementsOverride(ptor.driver);
} else {
return ptor.driver.findElements(self.locator_);
}
});
}
};

Expand Down Expand Up @@ -470,8 +472,13 @@ var buildElementHelper = function(ptor) {
WEB_ELEMENT_FUNCTIONS.forEach(function(fnName) {
if(!self[fnName]) {
self[fnName] = function() {
var webElem = self.getWebElement();
var actionResult = webElem[fnName].apply(webElem, arguments);
var args = arguments;
var webElem = self.getWebElement();
var actionResult = webElem.then(
function(webElem_) {
return webElem_[fnName].apply(webElem_, args);
});

return new ElementFinder(
locator, opt_parentElementFinder,
actionResult, opt_index);
Expand Down Expand Up @@ -722,11 +729,9 @@ var buildElementHelper = function(ptor) {
* @return {webdriver.promise.Promise} Promise which contains the results of
* evaluating fn.
*/
ElementFinder.prototype.then = function(fn) {
ElementFinder.prototype.then = function(fn, errorFn) {
if (this.opt_actionResult_) {
return this.opt_actionResult_.then(function() {
return fn.apply(null, arguments);
});
return this.opt_actionResult_.then(fn, errorFn);
} else {
return fn(this);
}
Expand Down
13 changes: 13 additions & 0 deletions spec/basic/elements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ describe('ElementFinder', function() {
expect(element(byCss).locator()).toEqual(byCss);
expect(element(byBinding).locator()).toEqual(byBinding);
});

it('should propagate exceptions', function() {
browser.get('index.html#/form');
var successful = protractor.promise.defer();

var invalidElement = element(by.binding('INVALID'));
invalidElement.getText().then(function(value) {
successful.fulfill(true);
}, function(err) {
successful.fulfill(false);
});
expect(successful).toEqual(false);
});
});

describe('evaluating statements', function() {
Expand Down

0 comments on commit 36e0e0a

Please sign in to comment.