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

protractor can't find nested elements when using by.repeater and ng-repeat-start #2365

Closed
jjulicher opened this issue Jul 20, 2015 · 5 comments

Comments

@jjulicher
Copy link

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.

@sjelin
Copy link
Contributor

sjelin commented Jul 21, 2015

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?

@jjulicher
Copy link
Author

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.

@sjelin
Copy link
Contributor

sjelin commented Jul 21, 2015

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.

@jjulicher
Copy link
Author

Thanks for the update!

sjelin added a commit to sjelin/protractor that referenced this issue Jul 22, 2015
This bug was introduced when by.exactRepeater was

Discovered while investigating issue angular#2365
@sjelin
Copy link
Contributor

sjelin commented Jul 22, 2015

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: #2368

@sjelin sjelin closed this as completed Jul 22, 2015
@sjelin sjelin removed the type: bug label Jul 22, 2015
sjelin added a commit to sjelin/protractor that referenced this issue Nov 9, 2015
This bug was introduced when by.exactRepeater was

Discovered while investigating issue angular#2365
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants