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.
Your webapp is brokem. You have:
<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>
But t is actually out of scope in t2 in t.nestedElements. You want :
<tr ng-repeat-start="t in tests">
<td>{{t.name}}</td>
<tr ng-repeat-start="t2 in t.nestedElements">
<td>{{t2.name}}</td>
</tr>
</tr>
But isn't the scope till the last ng-repeat-end? If it was out of scope it wouldn't run correct - but I actually ran this app and checked it's out put.. it is in scope.
Here is a full repo with all the code and tests: https://github.com/jjulicher/NestedRepeaterTest
As it renders correctly in my actual app - this was a demo to actually show the issue.
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.
So can you please re-open this?