Bird
Raised Fist0
Cypresstesting~20 mins

cy.check() and cy.uncheck() in Cypress - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Checkbox Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the result of this Cypress test snippet?
Consider this Cypress test code that interacts with checkboxes. What will be the state of the checkbox after running this test?
Cypress
cy.get('#subscribe').check().should('be.checked');
AThe checkbox will remain unchecked and the assertion will fail.
BThe test will throw an error because 'check()' cannot be chained with 'should()'.
CThe checkbox with id 'subscribe' will be checked and the assertion will pass.
DThe test will pass but the checkbox state will be undefined.
Attempts:
2 left
💡 Hint
Remember that cy.check() sets the checkbox to checked state and can be followed by assertions.
❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies a checkbox is unchecked after using cy.uncheck()?
You have a checkbox with id 'terms'. After running cy.get('#terms').uncheck(), which assertion correctly confirms it is unchecked?
Acy.get('#terms').should('be.visible');
Bcy.get('#terms').should('not.be.checked');
Ccy.get('#terms').should('have.value', 'unchecked');
Dcy.get('#terms').should('be.checked');
Attempts:
2 left
💡 Hint
Think about how to check if a checkbox is not selected.
❓ locator
advanced
2:00remaining
Which locator is best to select multiple checkboxes for cy.check()?
You want to check all checkboxes inside a form with id 'preferences'. Which locator is best to select all checkboxes for cy.check()?
Acy.get('#preferences')
Bcy.get('input')
Ccy.get('.checkbox')
Dcy.get('#preferences input[type="checkbox"]')
Attempts:
2 left
💡 Hint
Think about selecting only checkboxes inside the specific form.
🔧 Debug
advanced
2:00remaining
Why does this test fail when using cy.uncheck() on a disabled checkbox?
Given this code snippet, why does the test fail? cy.get('#promo').uncheck().should('not.be.checked'); The checkbox with id 'promo' is disabled in the HTML.
Acy.uncheck() cannot change the state of a disabled checkbox, so the checkbox remains checked and the assertion fails.
Bcy.uncheck() throws a syntax error when used on disabled elements.
CThe test fails because the selector '#promo' is incorrect.
DThe assertion is wrong; it should be 'be.checked' instead of 'not.be.checked'.
Attempts:
2 left
💡 Hint
Disabled form elements cannot be interacted with by user or automation.
❓ framework
expert
3:00remaining
How to correctly check multiple checkboxes with different values using cy.check()?
You have multiple checkboxes with name 'colors' and values 'red', 'green', 'blue'. Which code correctly checks only 'red' and 'blue' checkboxes?
Acy.get('input[name="colors"]').check(['red', 'blue']);
Bcy.get('input[name="colors"]').check('red', 'blue');
Ccy.get('input[name="colors"]').check({value: ['red', 'blue']});
Dcy.get('input[name="colors"]').check().filter(['red', 'blue']);
Attempts:
2 left
💡 Hint
Check the Cypress docs for checking multiple checkboxes by value.

Practice

(1/5)
1. What does cy.check() do in Cypress testing?
easy
A. Deselects checkboxes only
B. Clicks buttons on the page
C. Selects checkboxes or radio buttons
D. Types text into input fields

Solution

  1. Step 1: Understand the purpose of cy.check()

    cy.check() is used to select checkboxes or radio buttons in Cypress tests.
  2. Step 2: Compare with other commands

    cy.uncheck() is used to deselect checkboxes only, so it does not match the question.
  3. Final Answer:

    Selects checkboxes or radio buttons -> Option C
  4. Quick Check:

    cy.check() selects inputs [OK]
Hint: Remember: check() selects, uncheck() deselects checkboxes [OK]
Common Mistakes:
  • Confusing cy.check() with cy.uncheck()
  • Thinking cy.check() types text
  • Assuming cy.check() clicks buttons
2. Which of the following is the correct syntax to uncheck a checkbox with id agree in Cypress?
easy
A. cy.get('#agree').uncheck()
B. cy.get('#agree').check()
C. cy.get('#agree').click()
D. cy.get('#agree').type('uncheck')

Solution

  1. Step 1: Identify the command to deselect a checkbox

    To deselect a checkbox, use cy.uncheck().
  2. Step 2: Match the syntax with the element selector

    cy.get('#agree').uncheck() correctly targets the checkbox with id 'agree' and unchecks it.
  3. Final Answer:

    cy.get('#agree').uncheck() -> Option A
  4. Quick Check:

    uncheck() deselects checkbox [OK]
Hint: Use uncheck() only to deselect checkboxes [OK]
Common Mistakes:
  • Using check() to uncheck a box
  • Using click() which may toggle unpredictably
  • Trying to type 'uncheck' into checkbox
3. Given the following code snippet, what will be the assertion result?
cy.get('input[type="checkbox"]').check().should('be.checked');
cy.get('input[type="checkbox"]').uncheck().should('not.be.checked');
medium
A. First assertion passes, second fails
B. Both assertions pass
C. First assertion fails, second passes
D. Both assertions fail

Solution

  1. Step 1: Analyze the first command and assertion

    cy.get('input[type="checkbox"]').check() selects all checkboxes, then should('be.checked') asserts they are checked. This should pass.
  2. Step 2: Analyze the second command and assertion

    cy.get('input[type="checkbox"]').uncheck() deselects all checkboxes, then should('not.be.checked') asserts they are unchecked. This should also pass.
  3. Final Answer:

    Both assertions pass -> Option B
  4. Quick Check:

    check() then be.checked, uncheck() then not.be.checked [OK]
Hint: check() sets checked, uncheck() clears checked [OK]
Common Mistakes:
  • Assuming uncheck() works on radio buttons
  • Thinking check() does not affect checked state
  • Confusing assertion syntax
4. You wrote this Cypress test:
cy.get('input[type="radio"]').uncheck();

Why does this test fail?
medium
A. Because radio buttons cannot be selected
B. Because the selector is incorrect
C. Because uncheck() requires a parameter
D. Because uncheck() cannot be used on radio buttons

Solution

  1. Step 1: Understand uncheck() limitations

    uncheck() works only on checkboxes, not radio buttons.
  2. Step 2: Analyze the selector and usage

    The selector targets radio buttons, so using uncheck() causes failure.
  3. Final Answer:

    Because uncheck() cannot be used on radio buttons -> Option D
  4. Quick Check:

    uncheck() only for checkboxes [OK]
Hint: Use uncheck() only on checkboxes, not radios [OK]
Common Mistakes:
  • Trying to uncheck radio buttons
  • Assuming uncheck() needs parameters
  • Confusing selector correctness
5. You want to test a form with multiple checkboxes named 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?
hard
A. cy.get('input[name="features"]').check(['fast', 'secure']).should('be.checked')
B. cy.get('input[name="features"]').check('fast').check('secure').should('be.checked')
C. cy.get('input[name="features"]').check(['fast', 'secure']).should('have.value', ['fast', 'secure'])
D. cy.get('input[name="features"]').check(['fast', 'secure']).should('be.checked').uncheck('fast')

Solution

  1. Step 1: Use check() with array to select multiple checkboxes

    cy.get('input[name="features"]').check(['fast', 'secure']) checks the boxes with those values.
  2. Step 2: Assert that those checkboxes are checked

    should('be.checked') confirms the selected checkboxes are checked.
  3. Final Answer:

    cy.get('input[name="features"]').check(['fast', 'secure']).should('be.checked') -> Option A
  4. Quick Check:

    check(array) selects multiple, then assert checked [OK]
Hint: Use check(['val1','val2']) to select multiple checkboxes [OK]
Common Mistakes:
  • Using multiple check() calls without chaining properly
  • Using should('have.value') which is incorrect for checkboxes
  • Unchecking after checking without reason
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard