AngularJS:量角器:如何检索嵌套的ng-repeat标签

时间:2018-04-07 23:24:13

标签: javascript angularjs protractor

我是AngularJS的Protractor测试工具的新手。我有以下代码,我想使用Protractor

测试它

HTML部分

<table>
     <tr ng-repeat="row in rowcolumnsetup" id="{{$index}}">
         <td ng-repeat="column in rowcolumnsetup" id="{{$index}}" ng- 
                style="getClass($parent.$index,$index)"></td> 
     </tr>
</table>

的Javascript

var targetByRow = [[]];

//Setup Target Row

for(var row = 0 ; row < 7 ; row++) {
  targetByRow[row] = [7];

  for(var column = 0 ; column < 7 ; column++) {
    targetByRow[row][column] = {
            class : "",
            Status : ""
    };
  }
}

$scope.rowcolumnsetup = targetByRow;

现在在Protractor中的 spec.js 中,我想检查rowcolumnsetup在类或状态字段中是否有任何值。因此,为了访问rowcolumnsetup,我可以获取行但无法弄清楚如何检索列

element.all(by.repeater('row in rowcolumnsetup')).then(function(rows) {
  rows.forEach(function(row) {
    // Work in progress to retrieve column
  });
});

1 个答案:

答案 0 :(得分:0)

var tableData = element.all(by.repeater('row in rowcolumnsetup')).map(function(row) {
  var tds = row.all(by.css('td'));

  return {
     // give ng-style value of first td cell to class
     class: tds.get(0).getAttribute('ng-style'),
     // assume give the text of first td cell to status
     status: tds.get(0).getText()
  };
});

tableData.then(function(datas){
  //datas[0].class  ng-style value of first cell in first row
})