protractor can't find nested elements when using by.repeater and ng-repeat-start
When you use ng-repeat-start with nested objects protractor isn't exhibiting the expected behaviour.
I have create a test application to simulate this scenario with the following code:
Controller:
.controller('View1Ctrl', ['$scope',function ($scope) {
$scope.tests = [{
name: 'test1',
nestedElements: [{name: 'test1.subtest1'}, {name: 'test1.subtest2'}]
},
{
name: 'test2',
nestedElements: [{name: 'test2.subtest1'}, {name: 'test2.subtest2'}, {name: 'test2.subtest3'}]
}
];
}]);
View:
<table>
<tr ng-repeat-start="t in tests">
<td>{{t.name}}</td>
</tr>
<tr ng-repeat-start="t2 in t.nestedElements">
<td>{{t2.name}}</td>
</tr>
<tr ng-if="false" ng-repeat-end></tr>
<tr ng-if="false" ng-repeat-end></tr>
</table>
Protractor Test:
it('should get all the tests', function(){
var tests = element.all(by.repeater('t in tests'));
tests.then(function(e){
console.log('found ' + e.length + ' tests');
// expect(e.length).toBe(2);
for (var i = 0; i < e.length; i++) {
e[i].getInnerHtml().then(function(r){console.log(r);});
var subtasks = e[i].all(by.repeater('t2 in t.nestedElements'));
subtasks.getInnerHtml().then(function(r){console.log(r);});
expect(subtasks).toBeDefined();
}
});
});
I would expect that it would only return the 2 test objects not those plus the other nested ng-repeat objects.
Here is a full repo with all the code and tests: https://github.com/jjulicher/NestedRepeaterTest
@sjelin Please don't close this if you don't understand nested repeat elements.
As per the docs:
Special repeat start and end points To repeat a series of elements instead of just one parent element, ngRepeat (as well as other ng directives) supports extending the range of the repeater by defining explicit start and end points by using ng-repeat-start and ng-repeat-end respectively. The ng-repeat-start directive works the same as ng-repeat, but will repeat all the HTML code (including the tag it's defined on) up to and including the ending HTML tag where ng-repeat-end is placed.
Gotta love being lectured at :)
In your repo, is there any particular way you want me to start up the server for the app? Or should I just hop into /app/ and use httpster?
Sorry I was a little frustrated that it wasn't re-opened or did you not see my message in the other issue?
I was just using http-server - you could use httpster if you like too.
and just open a browser at http://localhost:8081/app/#/view1
that's the output. Run the protractor tests as normal.
Preliminary finding: our locators totally fail for ng-repeat-start. Assuming this really is the issue I'll have a PR fixing this later today.
Thanks for the update!
Ok, so, this is actually expected behavior (see the last example in http://angular.github.io/protractor/#/api?view=ProtractorBy.prototype.repeater). You should probably use a filter to get only the parts you want. As for why var subtasks = e[i].all(by.repeater('t2 in t.nestedElements')), it's because the elements which use the t2 repeater are not children of the elements using the t repeater. You did help me find a bug though: https://github.com/angular/protractor/pull/2368