Return array of value transporters from the repeater

I am looking for an easy way to return an array of values ​​from the protractor all.(by.repeater)

Basically, I just need an easy way to make a usernames array for the relay, like user in users .

Now I create it like this:

 allUsers = element.all(by.repeater('user in users').column('user.username')).then(function(array){ var results = [] var elemLength = array.length for(var n = 0; n < elemLength; n++){ array[n].getText().then(function(username){ results.push(username) }) } return results }); expect(allUsers).toContain(newUser) 

Is there a shorter, reusable way to do this built into the transporter / jasmine that I just can't find?

+6
source share
2 answers

AS alecxe said, use a card to do this. This will return a pending one, which will be resolved with the values ​​in the array, so if you have this:

 var mappedVals = element.all(by.repeater('user in users').column('user.username')).map(function (elm) { return elm.getText(); }); 

It will be resolved as follows:

 mappedVals.then(function (textArr) { // textArr will be an actual JS array of the text from each node in your repeater }); 
+11
source

I have successfully used map() for this before:

 element.all(by.repeater('user in users').column('user.username')).map(function (elm) { return elm.getText(); }); 

When I explored the topic, I made a decision:

+3
source

Source: https://habr.com/ru/post/975154/


All Articles