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

Commit

Permalink
fix(findelements): fix isPresent for repeaters by row for real
Browse files Browse the repository at this point in the history
  • Loading branch information
juliemr committed Nov 12, 2013
1 parent 8f9ffb6 commit f672648
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
31 changes: 31 additions & 0 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ clientSideScripts.findBindings = function() {
return rows[index];
};

/**
* Find an array of elements matching a row within an ng-repeat. There
* will only be one element, but this is necessary for isElementPresent.
*
* arguments[0] {Element} The scope of the search.
* arguments[1] {string} The text of the repeater, e.g. 'cat in cats'.
* arguments[2] {number} The row index.
*
* @return {Array.<Element>} An array of a single element, the row of the
* repeater.
*/
clientSideScripts.findRepeaterRows = function() {
var using = arguments[0] || document;
var repeater = arguments[1];
var index = arguments[2];

var rows = [];
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var attr = prefixes[p] + 'repeat';
var repeatElems = using.querySelectorAll('[' + attr + ']');
attr = attr.replace(/\\/g, '');
for (var i = 0; i < repeatElems.length; ++i) {
if (repeatElems[i].getAttribute(attr).indexOf(repeater) != -1) {
rows.push(repeatElems[i]);
}
}
}
return [rows[index]];
};

/**
* Find all rows of an ng-repeat.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/locators.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ ProtractorBy.prototype.repeater = function(repeatDescriptor) {
using, repeatDescriptor, index);
},
findArrayOverride: function(driver, using) {
return driver.findElement(
webdriver.By.js(clientSideScripts.findAllRepeaterRows),
using, repeatDescriptor);
return driver.findElements(
webdriver.By.js(clientSideScripts.findRepeaterRows),
using, repeatDescriptor, index);
},
column: function(binding) {
return {
Expand Down
8 changes: 8 additions & 0 deletions spec/basic/findelements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ describe('locators', function() {
column('qux'));
expect(byCol.getText()).toEqual('W');
});

it('should determine if repeater elements are present', function() {
expect(element(by.repeater('allinfo in days').row(3)).isPresent()).
toBe(true);
// There are only 5 rows, so the 6th row is not present.
expect(element(by.repeater('allinfo in days').row(5)).isPresent()).
toBe(false);
})
});

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

0 comments on commit f672648

Please sign in to comment.