Reputation: 697
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
<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">
<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
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