0
0
Cypresstesting~10 mins

Child commands in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses Cypress child commands to find a list and click a specific item inside it. It verifies that the clicked item has the expected text.

Test Code - Cypress
Cypress
describe('Child commands test', () => {
  it('Clicks a child item in a list and verifies text', () => {
    cy.visit('https://example.cypress.io/commands/actions')
    cy.get('.action-list')
      .find('li')
      .contains('Click')
      .click()
      .should('have.text', 'Click')
  })
})
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test startsCypress test runner initialized-PASS
2Browser opens and navigates to 'https://example.cypress.io/commands/actions'Page with action commands loaded, showing a list with class 'action-list'-PASS
3Find element with class '.action-list'List element found containing multiple <li> itemsElement '.action-list' existsPASS
4Within '.action-list', find all 'li' child elementsList items found inside '.action-list'Child 'li' elements existPASS
5From the 'li' elements, find the one containing text 'Click'Specific list item with text 'Click' foundList item text contains 'Click'PASS
6Click the found list itemList item clicked, page may respond to click-PASS
7Assert the clicked item has text 'Click'Text verified on clicked itemText equals 'Click'PASS
Failure Scenario
Failing Condition: The list item with text 'Click' is not found inside '.action-list'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the command '.find('li')' do in this test?
AIt verifies the text of the list
BIt clicks the first 'li' element on the page
CIt finds all 'li' child elements inside '.action-list'
DIt navigates to a new page
Key Result
Using child commands like '.find()' helps narrow down elements inside a parent, making tests more precise and easier to maintain.