0
0
Cypresstesting~10 mins

cy.find() within parent in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a webpage, locates a parent element, then uses cy.find() to find a child button inside it. It clicks the button and verifies the button text changes to confirm the click worked.

Test Code - Cypress
Cypress
describe('Test cy.find() within parent', () => {
  it('finds a button inside a parent and clicks it', () => {
    cy.visit('https://example.cypress.io/commands/actions')
    cy.get('.action-form')
      .find('button')
      .should('have.text', 'Submit')
      .click()
      .should('have.text', 'Clicked')
  })
})
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest runner initialized, no browser opened yet-PASS
2Browser opens and navigates to 'https://example.cypress.io/commands/actions'Page loaded with form containing a button labeled 'Submit'-PASS
3Find element with class '.action-form' using cy.get()Parent form element found on page-PASS
4Within the parent form, find the child 'button' element using cy.find()Button element inside form located with text 'Submit'Check button text is exactly 'Submit'PASS
5Click the found buttonButton clicked, page updates button text to 'Clicked'Verify button text changed to 'Clicked'PASS
6Test ends successfullyButton text confirmed changed, test passed-PASS
Failure Scenario
Failing Condition: Button inside the parent form is not found or text does not match 'Submit'
Execution Trace Quiz - 3 Questions
Test your understanding
What does cy.find() do in this test?
AClicks the parent element
BFinds any element on the page regardless of parent
CFinds a child element inside the previously found parent element
DNavigates to a new page
Key Result
Using cy.find() helps scope searches to a specific parent element, making tests more reliable and faster by avoiding searching the whole page.