如何检查特定单选按钮是否存在

时间:2016-08-18 17:02:05

标签: angularjs protractor

我需要有关量角器代码的帮助来检查两个单选按钮(是和否)是否存在。

对于是和没有单选按钮,HTML看起来像这样

对于无单选按钮html代码

<input required="required"
    class="ng-touched ng-valid ng-valid-required ng-dirty ng-valid-parse" 
    name="dangerousGood" id="dangerousGoodNo" data-ng-model="SLI.dangerous" 
    value="false" data-ng-required="true" 
    ng-change="updateCommodityType('N');isSrvLvlHazmat();errorMsgOnScreen.msg2 = false;" 
    type="radio">

For Yes单选按钮Html代码

<input required="required"
    class="ng-dirty ng-valid ng-valid-required ng-touched" 
    name="dangerousGood" data-ng-model="SLI.dangerous"
    value="true" data-ng-required="true" 
    ng-change="updateCommodityType('Y');isSrvLvlHazmat();"
    type="radio">

1 个答案:

答案 0 :(得分:1)

如果是在线状态而非可见性,则需要检查,只需使用element.all()查找两个输入并检查count()

var checkboxes = element.all(by.name("dangerousGood"));
expect(checkboxes.count()).toEqual(2);

您还可以使用by.model() locator

var checkboxes = element.all(by.model("SLI.dangerous"));

您还可以单独找到这两个复选框,断言状态/可见性并默认检查按钮is selected

var yesRadioButton = $("input[name=dangerousGood]:not(#dangerousGoodNo)");
var noRadioButton = $("input#dangerousGoodNo");

expect(yesRadioButton.isDisplayed()).toBe(true);
expect(noRadioButton.isDisplayed()).toBe(true);

expect(yesRadioButton.isSelected()).toBe(true);
expect(noRadioButton.isSelected()).toBe(false);