Test Overview
This test verifies that a checkbox can be checked and unchecked using Cypress commands cy.check() and cy.uncheck(). It confirms the checkbox state changes correctly.
This test verifies that a checkbox can be checked and unchecked using Cypress commands cy.check() and cy.uncheck(). It confirms the checkbox state changes correctly.
describe('Checkbox check and uncheck test', () => { it('should check and uncheck the checkbox', () => { cy.visit('https://example.com/form') cy.get('#subscribe-newsletter').check().should('be.checked') cy.get('#subscribe-newsletter').uncheck().should('not.be.checked') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to 'https://example.com/form' | Browser shows the form page with a checkbox having id 'subscribe-newsletter' | — | PASS |
| 3 | Find checkbox element with id 'subscribe-newsletter' using cy.get('#subscribe-newsletter') | Checkbox element is located on the page | — | PASS |
| 4 | Check the checkbox using cy.check() | Checkbox is now checked (ticked) | Verify checkbox is checked with .should('be.checked') | PASS |
| 5 | Find the same checkbox element again | Checkbox element is located and currently checked | — | PASS |
| 6 | Uncheck the checkbox using cy.uncheck() | Checkbox is now unchecked (unticked) | Verify checkbox is not checked with .should('not.be.checked') | PASS |
cy.check() do in Cypress testing?cy.check()cy.check() is used to select checkboxes or radio buttons in Cypress tests.cy.uncheck() is used to deselect checkboxes only, so it does not match the question.agree in Cypress?cy.uncheck().cy.get('#agree').uncheck() correctly targets the checkbox with id 'agree' and unchecks it.cy.get('input[type="checkbox"]').check().should('be.checked');
cy.get('input[type="checkbox"]').uncheck().should('not.be.checked');cy.get('input[type="checkbox"]').check() selects all checkboxes, then should('be.checked') asserts they are checked. This should pass.cy.get('input[type="checkbox"]').uncheck() deselects all checkboxes, then should('not.be.checked') asserts they are unchecked. This should also pass.cy.get('input[type="radio"]').uncheck();uncheck() limitationsuncheck() works only on checkboxes, not radio buttons.uncheck() causes failure.features. You want to check only the boxes with values fast and secure, then verify only those are checked. Which Cypress code snippet correctly does this?cy.get('input[name="features"]').check(['fast', 'secure']) checks the boxes with those values.should('be.checked') confirms the selected checkboxes are checked.Pass the test and this pattern moves unknown