1

例如,在 HTML 页面中:

<tr ng-repeat="post in posts">
    <td ng-click="activePost(post)" class="title">{{post.title}}</td>
    <td><button class="btn btn-danger" ng-click="delete(post)">Delete</button></td>
  <td><input type="checkbox" ng-model="post.active" 
        id="{{post.id}}" /></td>
 </tr>

然后,我想要类似的东西:

element.all(by.repeater('post in posts')).then(function(posts) {
   var activePost = posts[0].element(by.model('active'));
   expect(activePost).toEqual(true);
});

这将返回一个无法找到的元素。我基于这个问题和答案: Protractor find element inside a repeater

4

1 回答 1

3

传入的值by.model()应该与页面上的一样:

var activePost = posts[0].element(by.model('post.active'));

请注意,activePost变量将引用一个元素,因此即使它的值是false(未选中的复选框),expect(activePost).toEqual(true);也会满足预期。您需要断言复选框的值,而不是使用isSelected()

expect(activePost.isSelected()).toBeTruthy();
于 2015-01-23T15:53:31.300 回答