Reputation: 9
I have the following code, which is responsible for the state of a checkbox slider (on/off).
When the button is on:
<div _ngcontent-ofr-c662="" class="pull-right switch switch-small">
<div _ngcontent-ofr-c662="" class="col-auto"><label _ngcontent-ofr-c662="" class="o-switch">
<input _ngcontent-ofr-c662="" type="checkbox" ng-reflect-model="true" ng-reflect-is-disabled="false" ng-reflect-options="[object Object]" class="ng-untouched ng-valid ng-dirty"><span _ngcontent-ofr-c662="" data-off="No" data-on="Yes" class="switch__obj"></span></label></div>
<label _ngcontent-ofr-c662="" for="chkAllowCancelOrReschedule"></label>
</div>
And when the button is off:
<div _ngcontent-ofr-c662="" class="pull-right switch switch-small">
<div _ngcontent-ofr-c662="" class="col-auto"><label _ngcontent-ofr-c662="" class="o-switch">
<input _ngcontent-ofr-c662="" type="checkbox" ng-reflect-model="false" ng-reflect-is-disabled="false" ng-reflect-options="[object Object]" class="ng-untouched ng-valid ng-dirty"><span _ngcontent-ofr-c662="" data-off="No" data-on="Yes" class="switch__obj"></span></label></div>
<label _ngcontent-ofr-c662="" for="chkAllowCancelOrReschedule"></label>
</div>
The only state that changes is that of the variable ng-reflect-model
How can I check this status and if it is true, press that button, and if it is off nothing happens and the test continues?
I hope I put all the details and didn't miss something.
Thank you.
Upvotes: 0
Views: 255
Reputation: 4385
Look at the value of the attribute using jQuery .attr()
, like this
cy.get('input').then($el => {
if ($el.attr('ng-reflect-model') === 'false') {
cy.wrap($el).check()
}
})
Upvotes: 2