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

Commit f672648

Browse files
committed
fix(findelements): fix isPresent for repeaters by row for real
1 parent 8f9ffb6 commit f672648

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

lib/clientsidescripts.js

+31
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,37 @@ clientSideScripts.findBindings = function() {
108108
return rows[index];
109109
};
110110

111+
/**
112+
* Find an array of elements matching a row within an ng-repeat. There
113+
* will only be one element, but this is necessary for isElementPresent.
114+
*
115+
* arguments[0] {Element} The scope of the search.
116+
* arguments[1] {string} The text of the repeater, e.g. 'cat in cats'.
117+
* arguments[2] {number} The row index.
118+
*
119+
* @return {Array.<Element>} An array of a single element, the row of the
120+
* repeater.
121+
*/
122+
clientSideScripts.findRepeaterRows = function() {
123+
var using = arguments[0] || document;
124+
var repeater = arguments[1];
125+
var index = arguments[2];
126+
127+
var rows = [];
128+
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
129+
for (var p = 0; p < prefixes.length; ++p) {
130+
var attr = prefixes[p] + 'repeat';
131+
var repeatElems = using.querySelectorAll('[' + attr + ']');
132+
attr = attr.replace(/\\/g, '');
133+
for (var i = 0; i < repeatElems.length; ++i) {
134+
if (repeatElems[i].getAttribute(attr).indexOf(repeater) != -1) {
135+
rows.push(repeatElems[i]);
136+
}
137+
}
138+
}
139+
return [rows[index]];
140+
};
141+
111142
/**
112143
* Find all rows of an ng-repeat.
113144
*

lib/locators.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ ProtractorBy.prototype.repeater = function(repeatDescriptor) {
162162
using, repeatDescriptor, index);
163163
},
164164
findArrayOverride: function(driver, using) {
165-
return driver.findElement(
166-
webdriver.By.js(clientSideScripts.findAllRepeaterRows),
167-
using, repeatDescriptor);
165+
return driver.findElements(
166+
webdriver.By.js(clientSideScripts.findRepeaterRows),
167+
using, repeatDescriptor, index);
168168
},
169169
column: function(binding) {
170170
return {

spec/basic/findelements_spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ describe('locators', function() {
226226
column('qux'));
227227
expect(byCol.getText()).toEqual('W');
228228
});
229+
230+
it('should determine if repeater elements are present', function() {
231+
expect(element(by.repeater('allinfo in days').row(3)).isPresent()).
232+
toBe(true);
233+
// There are only 5 rows, so the 6th row is not present.
234+
expect(element(by.repeater('allinfo in days').row(5)).isPresent()).
235+
toBe(false);
236+
})
229237
});
230238

231239
it('should determine if an element is present', function() {

0 commit comments

Comments
 (0)