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.
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.
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') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner initialized | — | PASS |
| 2 | Browser opens and navigates to 'https://example.cypress.io/commands/actions' | Page with action commands loaded, showing a list with class 'action-list' | — | PASS |
| 3 | Find element with class '.action-list' | List element found containing multiple <li> items | Element '.action-list' exists | PASS |
| 4 | Within '.action-list', find all 'li' child elements | List items found inside '.action-list' | Child 'li' elements exist | PASS |
| 5 | From the 'li' elements, find the one containing text 'Click' | Specific list item with text 'Click' found | List item text contains 'Click' | PASS |
| 6 | Click the found list item | List item clicked, page may respond to click | — | PASS |
| 7 | Assert the clicked item has text 'Click' | Text verified on clicked item | Text equals 'Click' | PASS |
.find() command do in Cypress testing?.find().find() command is used to search for elements inside another element, meaning it looks for child elements..click(), .type(), and .wait() perform actions or wait, but do not locate child elements..find() locates children = B [OK]button inside a div with class container using Cypress?cy.get() selects the parent element. Then, .find() locates child elements inside it.cy.get('.container') to select the parent, then .find('button') to find the child button. Other options misuse the order or commands.cy.get('ul.menu').find('li.active').should('have.length', 2)cy.get('ul.menu') selects the ul element with class menu. Then .find('li.active') finds li children with class active..should('have.length', 2) asserts that exactly 2 such li.active elements exist inside the ul.menu.li elements inside ul.menu with class active and checks there are 2. -> Option Acy.find('.list').get('li').should('have.length', 3)cy.find() is not a valid starting command. cy.get() must be used first to select the parent element.cy.get('.list').find('li') to find li children inside the element with class list.form with id login contains exactly 3 input fields that are visible. Which Cypress code correctly uses child commands to do this?cy.get('#login') to select the form with id 'login'..find('input:visible') to get visible input fields inside the form, then assert there are exactly 3 with .should('have.length', 3).Pass the test and this pattern moves unknown