0
0
Cypresstesting~20 mins

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

Choose your learning style9 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.