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

Commit

Permalink
fix(protractor): make ElementFinder.then resolve to itself instead of…
Browse files Browse the repository at this point in the history
… null
  • Loading branch information
hankduan committed Jun 17, 2014
1 parent 31d42a3 commit a43f983
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ var buildElementHelper = function(ptor) {
}
this.locator_ = locator;
this.parentElementFinder_ = opt_parentElementFinder || null;
this.actionResult_ = opt_actionResult || webdriver.promise.fulfilled(null);
this.opt_actionResult_ = opt_actionResult;
this.opt_index_ = opt_index;

var self = this;
Expand Down Expand Up @@ -637,9 +637,13 @@ var buildElementHelper = function(ptor) {
* evaluating fn.
*/
ElementFinder.prototype.then = function(fn) {
return this.actionResult_.then(function() {
return fn.apply(null, arguments);
});
if (this.opt_actionResult_) {
return this.opt_actionResult_.then(function() {
return fn.apply(null, arguments);
});
} else {
return fn(this);
}
};

var element = function(locator) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"request": "~2.36.0",
"selenium-webdriver": "2.42.0",
"minijasminenode": "0.4.0",
"jasminewd": "1.0.0",
"jasminewd": "1.0.1",
"saucelabs": "~0.1.0",
"glob": "~3.2",
"adm-zip": "0.4.4",
Expand Down
20 changes: 20 additions & 0 deletions spec/basic/locators_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ describe('locators', function() {
expect(greeting.getText()).toEqual('Hiya');
});

it('should allow custom expectations to expect an element', function() {
this.addMatchers({
toHaveText: function(actualText) {
return this.actual.getText().then(function(expectedText) {
return expectedText === actualText;
});
}
});

expect(element(by.binding('{{greeting}}'))).toHaveText('Hiya');
});

it('ElementFinder.then should resolve to itself', function() {
var elem = element(by.binding('{{greeting}}'));

elem.then(function(elem2) {
expect(elem).toEqual(elem2);
});
});

it('should find a binding by partial match', function() {
var greeting = element(by.binding('greet'));

Expand Down

0 comments on commit a43f983

Please sign in to comment.