Balaji Singh .Y
Balaji Singh .Y

Reputation: 697

How to check specific radio buttons are present

I need help with protractor code to check whether both radio buttons ( yes and no ) are present or not.

The HTML looks like this for yes and no radio buttons

For No radio button html code

<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 Radio button Html code

<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">

Upvotes: 0

Views: 338

Answers (1)

alecxe
alecxe

Reputation: 474211

If it is the presence, and not visibility, you need to check, just use element.all() to find both inputs and check the count():

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

You can also use the by.model() locator:

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

You can also find both checkboxes separately, assert the presence/visibility and check what button is selected by default:

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);

Upvotes: 1

Related Questions