在量角器中,如何处理重复内容,例如表格?例如,给定下面的代码,即踢出一个表3列:Index,Name并且Delete-Button在每一行中:
<table class="table table-striped">
<tr ng-repeat="row in rows | filter : search" ng-class="{'muted':isTemp($index)}">
<td>{{$index+1}}</td>
<td>{{row}}</td>
<td>
<button class="btn btn-danger btn-mini" ng-click="deleteRow(row)" ng-hide="isTemp($index)"><i class="icon-trash icon-white"></i></button>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我需要根据给定的名称单击删除按钮.在Protractor中找到这个的最佳方法是什么?
我知道我可以抓取rows.colum({{row}})文本,得到它的索引,然后点击button[index],但我希望有一个更优雅的解决方案.
例如,在Geb中,您可以将行定位器传递给模块,然后使用列指示符对每行进行切块.那个解决方案让我盯上了Protractors的地图方法......
您可以使用地图或过滤器.api看起来像这样:
var name = 'some name';
// This is like element.all(by.css(''))
return $$('.table.table-stripe tr').filter(function(row) {
// Get the second column's text.
return row.$$('td').get(2).getText().then(function(rowName) {
// Filter rows matching the name you are looking for.
return rowName === name;
});
}).then(function(rows) {
// This is an array. Find the button in the row and click on it.
rows[0].$('button').click();
});
Run Code Online (Sandbox Code Playgroud)
http://angular.github.io/protractor/#/api?view=ElementArrayFinder.prototype.filter
| 归档时间: |
|
| 查看次数: |
16804 次 |
| 最近记录: |