Challenge - 5 Problems
Cypress Typing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the result of this Cypress test code?
Consider the following Cypress test snippet that types text into an input field. What will be the value of the input after running this code?
Cypress
cy.get('#username').type('hello').type('{backspace}').type('p'); cy.get('#username').invoke('val').then(value => cy.wrap(value));
Attempts:
2 left
💡 Hint
Remember that {backspace} removes the last character typed before it.
✗ Incorrect
The code types 'hello' into the input, then sends a backspace key which deletes the last character 'o', and finally types 'p'. So the final input value is 'hellp'.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the input value after typing?
You want to check that the input with id 'email' contains the text 'test@example.com' after typing. Which assertion is correct?
Cypress
cy.get('#email').type('test@example.com');
Attempts:
2 left
💡 Hint
Input fields store typed text in the 'value' attribute, not as inner text.
✗ Incorrect
The correct way to check the typed text in an input is to assert the 'value' property. 'have.value' checks this correctly.
❓ locator
advanced2:30remaining
Which locator is best for typing into a password field with accessibility in mind?
You want to type into a password input field that has a label 'Password'. Which locator is the best practice for accessibility and reliability?
Attempts:
2 left
💡 Hint
Using the label's 'for' attribute links the label to the input, improving accessibility.
✗ Incorrect
Option C uses the label text to find the input by its 'for' attribute, which is the most accessible and reliable method.
🔧 Debug
advanced2:00remaining
Why does this Cypress test fail to type text into the input?
Look at this code snippet:
cy.get('#search').type('query');
But the test fails with error: "cy.type() failed because this element is disabled". What is the most likely cause?
Attempts:
2 left
💡 Hint
Cypress cannot type into inputs that are disabled by HTML attributes.
✗ Incorrect
The error message indicates the input is disabled, so Cypress cannot type into it. The 'disabled' attribute blocks user input.
❓ framework
expert2:30remaining
How to simulate typing with delay between keystrokes in Cypress?
You want to simulate a user typing slowly into an input with id 'comment'. Which code snippet correctly types 'hello' with a 100ms delay between each character?
Attempts:
2 left
💡 Hint
Check the official Cypress docs for the correct option name for delay.
✗ Incorrect
The 'delay' option in cy.type() adds a delay between each keystroke. Option B uses it correctly.