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

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

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

<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 字符串的内容。这里有什么建议吗?

问题其实出在`allButtons.getText().

此函数正在 angular 元素上应用,结果是连接符合条件的所有内容:button。 (这是基于 ng-repeat 的 N,因此给你数组)。

请检查是否可以,根据 allButtons 属性,找到您最感兴趣的。例如:

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

编辑:修复断言以使用 first() 而不是 elementAt(0),如 @alecxe

所述

虽然 .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');
});

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