Test Overview
This test opens a webpage with a dropdown menu, selects an option using cy.select(), and verifies the correct option is selected.
This test opens a webpage with a dropdown menu, selects an option using cy.select(), and verifies the correct option is selected.
describe('Dropdown selection test', () => { it('selects an option from the dropdown and verifies it', () => { cy.visit('https://example.com/dropdown') cy.get('#fruits').select('Banana') cy.get('#fruits').should('have.value', 'Banana') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner initialized, no browser opened yet | — | PASS |
| 2 | Browser opens and navigates to 'https://example.com/dropdown' | Browser shows the dropdown page with id 'fruits' | — | PASS |
| 3 | Finds dropdown element with id '#fruits' | Dropdown element is visible and enabled | — | PASS |
| 4 | Selects option 'Banana' from the dropdown using cy.select('Banana') | Dropdown option 'Banana' is selected | — | PASS |
| 5 | Asserts dropdown value is 'Banana' using should('have.value', 'Banana') | Dropdown value is 'Banana' | Verify dropdown value equals 'Banana' | PASS |
cy.select() command do in Cypress testing?cy.select()cy.select() command is designed specifically to choose options from dropdown menus in Cypress tests.cy.type(), clicking uses cy.click(), and waiting uses cy.wait(). So, cy.select() is unique for dropdowns.cy.select()?cy.select() syntaxcy.get(), then call .select() with the visible text as argument.selectByText() or choose() method in Cypress. Also, cy.select() is not called directly with selector and text.cy.get('#colors').select('blue').should('have.value', 'blue')cy.get('select#country').select(2).should('have.value', 'US')cy.select() accepts visible text, value, or an array of these. Selecting by index number directly (like 2) is not supported.select#country is valid CSS. The assertion should('have.value', 'US') is correct to check the selected value.cy.select()?cy.select().select() calls does not accumulate selections. Passing a comma-separated string selects one option matching that exact string, which is invalid.Pass the test and this pattern moves unknown