Recall & Review
beginner
What is a parent command in Cypress?
A parent command is a Cypress command that starts a chain of commands. It selects elements or triggers actions and returns a subject for further commands.
Click to reveal answer
beginner
How does the
cy.get() command act as a parent command?cy.get() selects elements from the page and returns them as a subject for chaining more commands like .click() or .should().Click to reveal answer
beginner
Why are parent commands important in Cypress test scripts?
Parent commands start the command chain and provide the elements or context needed for child commands to work on, enabling clear and readable tests.
Click to reveal answer
beginner
Example: What does this Cypress code do? <br>
cy.get('button').click()It uses the parent command
cy.get('button') to find all button elements, then clicks the first button found using the child command .click().Click to reveal answer
intermediate
Can a parent command be chained with multiple child commands? Give an example.
Yes. For example: <br>
cy.get('input').type('hello').should('have.value', 'hello') <br>The parent command cy.get('input') selects the input, then child commands type text and check the value.Click to reveal answer
Which of these is a parent command in Cypress?
✗ Incorrect
cy.get() is a parent command that starts a chain by selecting elements. The others are child commands that act on the selected elements.
What does a parent command return in Cypress?
✗ Incorrect
Parent commands return a subject (like elements) so you can chain child commands to perform actions or assertions.
Which command chain is correct in Cypress?
✗ Incorrect
You must start with a parent command like cy.get() before chaining child commands like .click().
What happens if you try to use a child command without a parent command first?
✗ Incorrect
Child commands need a subject from a parent command. Without it, Cypress will throw an error.
Which of these is NOT a parent command in Cypress?
✗ Incorrect
.click() is a child command that acts on elements selected by a parent command.
Explain what a parent command is in Cypress and why it is necessary.
Think about how Cypress finds elements to work with.
You got /4 concepts.
Describe how you would use a parent command and child commands together in a simple test.
Imagine clicking a button after finding it.
You got /4 concepts.