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

Commit 30c0ceb

Browse files
committed
feat(element) element.all exports an 'each' method
Usage: ``` element.all(by.model('foo')).each(function(webElement) { // Do stuff with webElement. }); ``` Closes #298
1 parent 238bb74 commit 30c0ceb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/protractor.js

+8
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ var buildElementHelper = function(ptor) {
131131
return ptor.findElements(locator).then(fn);
132132
};
133133

134+
elementArrayFinder.each = function(fn) {
135+
ptor.findElements(locator).then(function(arr) {
136+
arr.forEach(function(webElem) {
137+
fn(webElem);
138+
});
139+
});
140+
};
141+
134142
return elementArrayFinder;
135143
}
136144

spec/basic/findelements_spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ describe('global element function', function() {
362362
expect(colorList.last(0).getAttribute('value')).toEqual('red');
363363
});
364364

365+
it('should perform an action on each element in an array', function() {
366+
var colorList = element.all(by.model('color'));
367+
colorList.each(function(colorElement) {
368+
expect(colorElement.getText()).not.toEqual('purple');
369+
});
370+
});
371+
365372
it('should export an isPresent helper', function() {
366373
expect(element(by.binding('greet')).isPresent()).toBe(true);
367374
expect(element(by.binding('nopenopenope')).isPresent()).toBe(false);

0 commit comments

Comments
 (0)