Tyler Agnew
Tyler Agnew

Reputation: 93

Can I get back an array in Protractor by.Repeater rather than a string?

I have an ng-repeat directive that I am looking to use the Protractor repeater to get back an array:

<div ng-repeat="product in landingPage.products" class="landing-buttons">
    <a ui-sref="personalInfo">
    <button type="button" class="btn btn-primary btn-block">{{product}}</button></a>
</div>

I just want the {{product}} string to come back in an array, but I just get what looks like a JSON string instead. Any suggestions here?

Upvotes: 2

Views: 100

Answers (2)

Tyler Agnew
Tyler Agnew

Reputation: 93

While .first() helped me get the first element, for any subsequent ones I used .get(index).

it('should have buttons', function () {
expect(landingPage.allButtons.first().getText()).toEqual('Accident & Health');
expect(landingPage.allButtons.get(1).getText()).toEqual('Disability');
expect(landingPage.allButtons.get(2).getText()).toEqual('Life');
});

This works now. Thanks all for your help.

Upvotes: 1

Custodio
Custodio

Reputation: 8934

The problem is actually on the `allButtons.getText().

This function is being applied over the angular element and the result is the concatenation of everything that matches the criteria: button. (Which are N based on the ng-repeat, and therefore gives you the array).

Please check if you can, base on the allButtons attribute, find the one the interest you the most. e.g:

expect(landingPage.allButtons.first().getText()).toEqual('Accident & Health');

Edit: Fixing the assertion to use first() instead elementAt(0) as mentioned by @alecxe

Upvotes: 1

Related Questions