diff --git a/lib/protractor.js b/lib/protractor.js index f43dbf2a0..bc24738b4 100644 --- a/lib/protractor.js +++ b/lib/protractor.js @@ -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; @@ -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) { diff --git a/package.json b/package.json index d77fa50a0..5871f51bd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/spec/basic/locators_spec.js b/spec/basic/locators_spec.js index ad0cf6297..879cf6578 100644 --- a/spec/basic/locators_spec.js +++ b/spec/basic/locators_spec.js @@ -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'));