量角器:查找具有匹配单元格值的表格行

时间:2016-06-13 15:31:54

标签: angularjs protractor

是否可以使用表格单元格中应存在的确切值在ng-repeat中找到表格行?

我知道我可以使用以下语法检索特定列:

element(by.repeater('customer in vm.customers').row(0).column('customer.name')

在我的情况下,我不知道索引是什么。

所以说我有一个典型的表声明:

<table>
    <tr ng-repeat="customer in customers">
        <td>
            {{customer.firstName}}
        </td>
        <td>
            {{customer.lastName}}
        </td>
    </tr>
</table>

我得到以下输出

<table>
    <tr>
        <td>
            Bob
        </td>
        <td>
            Smith
        </td>
    </tr>
    <tr>
        <td>
            James
        </td>
        <td>
            Tulley
        </td>
    </tr>
</table>

我可以用一个定位器来说明让我看到包含Bob Smith的行吗? 我知道这不是很漂亮但是像:

element(by.repeater('customer in vm.customers').column('customer.firstName=James').column('customer.lastName=James')

我的用例是在表单视图上编辑记录后,用户被发送回表视图,我想在其上检查值是否确实更新过。

是否有任何有用的食谱\方法可以帮助到这里?

2 个答案:

答案 0 :(得分:0)

您可以使用XPath通过一次调用来匹配转发器和行中的文本:

element(by.xpath("//tr[@ng-repeat='customer in customers'][normalize-space(.)='Bob Smith']"))

答案 1 :(得分:-2)

看看我的量角器codelab。我做了一个非常相似的练习。以下是代码:https://github.com/andresdominguez/protractor-codelab/blob/ex3-solution/spec/list-helper.js#L13

测试看起来像:

it('should add user', function() {
  var name = 'test name ' + uniqueId;
  var email = 'foo' + uniqueId + '@gmail.com';
  var phone = '212-555-0000';

  userList.addUserButton.click();

  userProperties.name.sendKeys(name);
  userProperties.email.sendKeys(email);
  userProperties.phone.sendKeys(phone);
  userProperties.saveButton.click();

  expect(userList.list.getUsersByName(name)).toEqual([{
    name: name,
    email: email,
    phone: phone
  }]);
});

参见测试:https://github.com/andresdominguez/protractor-codelab/blob/ex3-solution/spec/ex3-solution-spec.js#L13