我已经看到如何通过此链接选中一个复选框: How to validate when a checkbox is checked in AngularJS e2e tests?
但是我想知道如何执行此操作以检查我 View 中的所有复选框是否都将被选中。
目前下面的代码只检查一个复选框是否被选中:
.clickElementById('user-' + data.userIndex)
.expect(
element('input[ng-model="user.checked"]')
.attr('checked')
).toBeTruthy()
这正是我想要的,但是当我进行下一次通过按钮选择所有复选框的测试时,我想遍历所有复选框以测试它们是否已被选中。抱歉重复一遍。
他
最佳答案
使用 element.all
创建指定元素的数组,然后您可以循环或直接调用它们,即
element.all(by.model('user.checked').then(function(btn) {
expect(btn[0].attr('checked')).toBe('true');
});
或者用循环
element.all(by.model('user.checked').each(function(btn) {
// iterates through each btn
expect(btn.attr('checked')).toBe('true');
});
来源:https://angular.github.io/protractor/#/api?view=ElementArrayFinder
关于javascript - 如何在 Protractor 中选中多个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36738017/