我可以在Protractor by.Repeater而不是字符串中找回一个数组吗?

时间:2015-10-19 19:49:04

标签: arrays angularjs automation protractor

我有一个ng-repeat指令,我希望使用Protractor转发器来取回一个数组:

<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>

我只希望{{product}}字符串返回数组,但我只是得到了一个类似于JSON字符串的内容。这里有什么建议吗?

2 个答案:

答案 0 :(得分:1)

问题实际上在`allButtons.getText()。

此功能应用于角度元素,结果是符合条件的所有内容的串联:按钮。 (这是基于ng-repeat的N,因此为您提供数组)。

请根据allButtons属性检查您是否可以找到您最感兴趣的属性。 e.g:

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

编辑:修复断言以使用first()而不是@Alecxe 提到的elementAt(0)

答案 1 :(得分:1)

虽然.first()帮助我获得了第一个元素,但对于我后来使用的任何元素.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');
});

现在可以使用了。谢谢大家的帮助。