diff --git a/lib/element.js b/lib/element.js index 9f7b81aa0..34a4fa984 100644 --- a/lib/element.js +++ b/lib/element.js @@ -953,6 +953,20 @@ ElementFinder.prototype.allowAnimations = function(value) { return this.elementArrayFinder_.allowAnimations(value).toElementFinder_(); }; + +/** + * Compares an element to this one for equality. + * + * @param {!ElementFinder|!webdriver.WebElement} The element to compare to. + * + * @return {!webdriver.promise.Promise.} A promise that will be + * resolved to whether the two WebElements are equal. + */ +ElementFinder.prototype.equals = function(element) { + return webdriver.WebElement.equals(this.getWebElement(), + element.getWebElement ? element.getWebElement() : element); +}; + /** * Shortcut for querying the document directly with css. * `element(by.css('.abc'))` is equivalent to `$('.abc')` diff --git a/spec/basic/elements_spec.js b/spec/basic/elements_spec.js index c433cac16..deb4d0936 100644 --- a/spec/basic/elements_spec.js +++ b/spec/basic/elements_spec.js @@ -186,6 +186,16 @@ describe('ElementFinder', function() { ).toEqual('Anon'); }); + + it('should check equality correctly', function() { + browser.get('index.html#/form'); + + var usernameInput = element(by.model('username')); + var name = element(by.binding('username')); + + expect(usernameInput.equals(usernameInput)).toEqual(true); + expect(usernameInput.equals(name)).toEqual(false); + }); }); describe('ElementArrayFinder', function() {