Skip to content

Commit

Permalink
feat(element) element.all exports an 'each' method
Browse files Browse the repository at this point in the history
Usage:
```
element.all(by.model('foo')).each(function(webElement) {
  // Do stuff with webElement.
});
```
Closes #298
  • Loading branch information
juliemr committed Dec 20, 2013
1 parent 238bb74 commit 30c0ceb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ var buildElementHelper = function(ptor) {
return ptor.findElements(locator).then(fn);
};

elementArrayFinder.each = function(fn) {
ptor.findElements(locator).then(function(arr) {
arr.forEach(function(webElem) {
fn(webElem);
});
});
};

return elementArrayFinder;
}

Expand Down
7 changes: 7 additions & 0 deletions spec/basic/findelements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ describe('global element function', function() {
expect(colorList.last(0).getAttribute('value')).toEqual('red');
});

it('should perform an action on each element in an array', function() {
var colorList = element.all(by.model('color'));
colorList.each(function(colorElement) {
expect(colorElement.getText()).not.toEqual('purple');
});
});

it('should export an isPresent helper', function() {
expect(element(by.binding('greet')).isPresent()).toBe(true);
expect(element(by.binding('nopenopenope')).isPresent()).toBe(false);
Expand Down

0 comments on commit 30c0ceb

Please sign in to comment.