Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor getText of WebElement in repeater array

In an html page I have:

<ul class="phones">
              <li ng-repeat="phone in phones | filter:query | orderBy: orderProp">
                {{phone.name}} - {{phone.age}}
                <p>{{phone.snippet}}</p>
              </li>
            </ul>

In an e2e test I have (is returning two elements in the array):

            var result= ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));

            result.then(function(arr) {
                arr[0].getText().then(function(text) {
                    console.log("*** 1: "+ text);
                });

                arr[1].getText().then(function(text) {
                    console.log("*** 2: "+ text);
                })
            });

The console is printing all three columns, phone.name, phone.age, and phone.snippet. Why is the selector not just returning phone.name?

Its actually returning whatever I have in the list "li", plain text or a binding.

like image 350
bmw0128 Avatar asked Nov 14 '13 20:11

bmw0128


1 Answers

The example tries to locate elements with the strategy below (column part is fixed as per comments):

protractor.By.repeater('phone in phones').column('name')

Repeater part matches the li element and then goes to find element(s) with phone.name binding. It's wrapping element happens to be the same li.

Changing column part to .column('snippet') returns p elements because phone.snippet binding is found inside of those.

Relevant docs/examples here: https://github.com/angular/protractor/blob/master/docs/getting-started.md#writing-tests

like image 118
Heikki Avatar answered Oct 13 '22 00:10

Heikki