我在使用 Protractor 检查 AngularJs 转发器中的复选框时遇到困难。
模型看起来像这样:
environments: [
{
name: 'Proof of Concept',
checked: false
},
{
name: 'Non-Production',
checked: false
},
{
name: 'Production',
checked: false
}
]
这样的 View :
<div class="checkbox" ng-repeat="environment in vm.assessment.environments">
<label><input type="checkbox" ng-model="vm.assessment.environments[$index].checked" ng-click="vm.checkboxChanged()" ng-required="!vm.someChecked">{{environment.name}}</label>
</div>
像这样在 Protractor 中获取中继器:
this.environments = element.all(by.repeater('environment in vm.assessment.environments'));
并尝试像这样检查复选框但是当我运行测试时它似乎没有检查它:
this.environments.get(0).click();
最佳答案
And trying to check the checkbox like this but when i run the test it does not seem to check it:
那是因为您正在单击转发器项目 - div
元素,但我怀疑您需要单击 input
子元素。
您可以在单个表达式中链接 .all()
和.element()
调用:
this.environments.first().element(by.css("input[ng-model$=checked]")).click();
关于angularjs - 如何用 Protractor 检查中继器中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37558845/