From 76861fdc4c57c2aaa984e05e46ff9789ce750260 Mon Sep 17 00:00:00 2001 From: Sammy Jelin Date: Wed, 6 Apr 2016 14:09:49 -0700 Subject: [PATCH] feat(element): equals Easier to use version of webdriver.WebElement.equals --- lib/element.js | 14 ++++++++++++++ spec/basic/elements_spec.js | 10 ++++++++++ 2 files changed, 24 insertions(+) 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() {