【发布时间】:2016-02-09 03:32:34
【问题描述】:
我有一个相当简单的量角器测试,它应该检查 ng-repeat 行中的文本值。
这是我的 HTML:
<div ng-repeat="destination in destinations">
<span>{{destination.city}}, {{destination.country}}</span>
</div>
这是我的 JS:
lastDestination = element.all(by.repeater('destination in destinations').row(1));
expect(lastDestination.getText()).toEqual("Madrid, Spain");
documentation for getText() 声明:
获取此元素的可见(即未被 CSS 隐藏)innerText,包括子元素,没有任何前导或尾随空格。
所以我希望从行的 span 标签中返回文本,但是在运行 Protractor 测试时,我收到以下断言错误:
预计 [ '马德里,西班牙' ] 等于 '马德里,西班牙'。
GetText() 似乎返回的是数组而不是字符串。
我尝试解决 getText() 的承诺,但仍然遇到同样的错误:
lastDestination = element.all(by.repeater('destination in destinations').row(1));
lastDestination.getText().then(function (text) {
expect(text).toEqual("Madrid, Spain");
});
我可以通过定位数组中的第一个值来解决这个问题:
expect(text[0]).toEqual("Madrid, Spain");
但我仍然想知道为什么这首先不起作用。
有什么想法吗?
更新:Protractor 的 Github 页面上的 similar bug has been reported,因此可能是 getText() 函数无法正常工作。
【问题讨论】:
标签: javascript angularjs protractor angularjs-e2e