如何在量角器中处理表格数据 [英] How to handle table data in Protractor

查看:34
本文介绍了如何在量角器中处理表格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Protractor 中,如何处理重复的内容,比如一张表格?例如,给定以下代码,它会在每行中踢出一个包含 3 列的表:IndexNameDelete-Button:

In Protractor, how does one handle repeated content, from say a table? For example, given the following code, that kicks out a table with 3 columns: Index, Name and Delete-Button in each row:

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

在我的测试中,我需要根据给定的名称单击删除按钮.在 Protractor 中找到它的最佳方法是什么?

And in my test I need to click the delete button based on a given name. What's the best way to find this in Protractor?

我知道我可以抓取 rows.colum({{row}}) 文本,获取它的索引,然后点击 button[index],但我希望有一个更优雅的解决方案.

I know I could grab the rows.colum({{row}}) text, get the index of that, and then click on the button[index], but I'm hoping for a more elegant solution.

例如,在 Geb 中,您可以将行定位器传递给模块,然后模块会用列指示符对每一行进行切块.这个解决方案让我关注量角器映射方法......

For example, in Geb, you could pass a row locator to a module, that would then dice up each row with column indicators. And that solution has me eyeing Protractors map method...

推荐答案

您可以使用映射或过滤器.api 看起来像这样:

You can use map or filter. The api would look like this:

  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();
  });

http://angular.github.io/protractor/#/api?view=ElementArrayFinder.prototype.filter

这篇关于如何在量角器中处理表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆