Test Overview
This test checks that a specific child element exists within a parent container on a webpage. It verifies that the child element is correctly nested inside the parent element using cy.parent() and cy.children() commands.
This test checks that a specific child element exists within a parent container on a webpage. It verifies that the child element is correctly nested inside the parent element using cy.parent() and cy.children() commands.
describe('Test cy.parent() and cy.children()', () => { it('verifies child element is inside the parent container', () => { cy.visit('https://example.cypress.io/commands/traversal') // Find the child element with class 'traversal-mark' cy.get('.traversal-mark') .should('exist') // Check its parent has class 'traversal-button-states' .parent() .should('have.class', 'traversal-button-states') // Then check the parent has children and one of them is the original child .children() .should('contain.text', 'Mark') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initializes the Cypress test environment | - | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io/commands/traversal' | The webpage with traversal commands examples is loaded | - | PASS |
| 3 | Find element with class '.traversal-mark' | The element with text 'Mark' inside the page is located | Check element exists | PASS |
| 4 | Get parent of '.traversal-mark' element | Parent element with class 'traversal-button-states' is selected | Verify parent has class 'traversal-button-states' | PASS |
| 5 | Get children of the parent element | All child elements inside the parent container are selected | Verify children contain text 'Mark' | PASS |
| 6 | Test ends successfully | All assertions passed, test completes | - | PASS |