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

Commit

Permalink
feat(element): equals
Browse files Browse the repository at this point in the history
Easier to use version of webdriver.WebElement.equals
  • Loading branch information
sjelin committed Apr 6, 2016
1 parent 4de9fb6 commit 76861fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<boolean>} 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')`
Expand Down
10 changes: 10 additions & 0 deletions spec/basic/elements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 76861fd

Please sign in to comment.