Skip to content
Advertisement

Verify the checkbox is checked in Cypress

I want to verify the checkbox is checked. This is the HTML for the checkbox

enter image description here

the js for it:

    localShopClerkcheckbox(){
        return cy.get("[name='isLocalClerk']")
        //return cy.get(':nth-child(4) > .dx-box-flex > :nth-child(2) > .dx-item-content > .dx-last-col > .dx-field-item-content > .dx-show-invalid-badge > .dx-checkbox-container > .dx-checkbox-icon')
    }

Then on step definition:

Then("I see the Local Shop clerk is selected",() =>{
    backofficeCreateDeleteClerkPage.localShopClerkcheckbox().should('have.attr','aria-checked',true)

})

strangely Cypress shows that the expected value was true but the value was true

enter image description here

Advertisement

Answer

You have to change true to 'true'. The true is a string.

backofficeCreateDeleteClerkPage
  .localShopClerkcheckbox()
  .should('have.attr', 'aria-checked', 'true')
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement