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

Commit 76861fd

Browse files
committed
feat(element): equals
Easier to use version of webdriver.WebElement.equals
1 parent 4de9fb6 commit 76861fd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/element.js

+14
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,20 @@ ElementFinder.prototype.allowAnimations = function(value) {
953953
return this.elementArrayFinder_.allowAnimations(value).toElementFinder_();
954954
};
955955

956+
957+
/**
958+
* Compares an element to this one for equality.
959+
*
960+
* @param {!ElementFinder|!webdriver.WebElement} The element to compare to.
961+
*
962+
* @return {!webdriver.promise.Promise.<boolean>} A promise that will be
963+
* resolved to whether the two WebElements are equal.
964+
*/
965+
ElementFinder.prototype.equals = function(element) {
966+
return webdriver.WebElement.equals(this.getWebElement(),
967+
element.getWebElement ? element.getWebElement() : element);
968+
};
969+
956970
/**
957971
* Shortcut for querying the document directly with css.
958972
* `element(by.css('.abc'))` is equivalent to `$('.abc')`

spec/basic/elements_spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ describe('ElementFinder', function() {
186186
).toEqual('Anon');
187187

188188
});
189+
190+
it('should check equality correctly', function() {
191+
browser.get('index.html#/form');
192+
193+
var usernameInput = element(by.model('username'));
194+
var name = element(by.binding('username'));
195+
196+
expect(usernameInput.equals(usernameInput)).toEqual(true);
197+
expect(usernameInput.equals(name)).toEqual(false);
198+
});
189199
});
190200

191201
describe('ElementArrayFinder', function() {

0 commit comments

Comments
 (0)