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

Commit a43f983

Browse files
committed
fix(protractor): make ElementFinder.then resolve to itself instead of null
1 parent 31d42a3 commit a43f983

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

lib/protractor.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ var buildElementHelper = function(ptor) {
377377
}
378378
this.locator_ = locator;
379379
this.parentElementFinder_ = opt_parentElementFinder || null;
380-
this.actionResult_ = opt_actionResult || webdriver.promise.fulfilled(null);
380+
this.opt_actionResult_ = opt_actionResult;
381381
this.opt_index_ = opt_index;
382382

383383
var self = this;
@@ -637,9 +637,13 @@ var buildElementHelper = function(ptor) {
637637
* evaluating fn.
638638
*/
639639
ElementFinder.prototype.then = function(fn) {
640-
return this.actionResult_.then(function() {
641-
return fn.apply(null, arguments);
642-
});
640+
if (this.opt_actionResult_) {
641+
return this.opt_actionResult_.then(function() {
642+
return fn.apply(null, arguments);
643+
});
644+
} else {
645+
return fn(this);
646+
}
643647
};
644648

645649
var element = function(locator) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"request": "~2.36.0",
1616
"selenium-webdriver": "2.42.0",
1717
"minijasminenode": "0.4.0",
18-
"jasminewd": "1.0.0",
18+
"jasminewd": "1.0.1",
1919
"saucelabs": "~0.1.0",
2020
"glob": "~3.2",
2121
"adm-zip": "0.4.4",

spec/basic/locators_spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ describe('locators', function() {
1010
expect(greeting.getText()).toEqual('Hiya');
1111
});
1212

13+
it('should allow custom expectations to expect an element', function() {
14+
this.addMatchers({
15+
toHaveText: function(actualText) {
16+
return this.actual.getText().then(function(expectedText) {
17+
return expectedText === actualText;
18+
});
19+
}
20+
});
21+
22+
expect(element(by.binding('{{greeting}}'))).toHaveText('Hiya');
23+
});
24+
25+
it('ElementFinder.then should resolve to itself', function() {
26+
var elem = element(by.binding('{{greeting}}'));
27+
28+
elem.then(function(elem2) {
29+
expect(elem).toEqual(elem2);
30+
});
31+
});
32+
1333
it('should find a binding by partial match', function() {
1434
var greeting = element(by.binding('greet'));
1535

0 commit comments

Comments
 (0)