bmw*_*128 6 angularjs protractor
在一个html页面中,我有:
<ul class="phones">
<li ng-repeat="phone in phones | filter:query | orderBy: orderProp">
{{phone.name}} - {{phone.age}}
<p>{{phone.snippet}}</p>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
在e2e测试中我有(返回数组中的两个元素):
var result= ptor.findElements(protractor.By.repeater('phone in phones').column('phone.name'));
result.then(function(arr) {
arr[0].getText().then(function(text) {
console.log("*** 1: "+ text);
});
arr[1].getText().then(function(text) {
console.log("*** 2: "+ text);
})
});
Run Code Online (Sandbox Code Playgroud)
控制台正在打印所有三列,phone.name,phone.age和phone.snippet.为什么选择器不仅仅是返回phone.name?
它实际上返回列表"li",纯文本或绑定中的任何内容.
该示例尝试使用以下策略来定位元素(列部分根据注释进行固定):
protractor.By.repeater('phone in phones').column('name')
Run Code Online (Sandbox Code Playgroud)
转发器部分匹配li元素,然后查找具有phone.name绑定的元素。它的包装元素恰好是相同的li。
更改列部分以.column('snippet')返回p元素,因为phone.snippet在这些元素内部找到了绑定。
相关文档/示例在这里:https://github.com/angular/protractor/blob/master/docs/getting-started.md#writing-tests
| 归档时间: |
|
| 查看次数: |
10300 次 |
| 最近记录: |