cy.get('#fruits').select('Banana').should('have.value', 'banana')
The select() command chooses the option with visible text 'Banana'. The assertion checks if the dropdown's value is 'banana', which matches the option's value attribute. Since both match, the test passes.
cy.select(). Which assertion is correct?cy.get('#colors').select('Red')
The have.value assertion checks the value attribute of the selected option. 'contain' and 'have.text' check the element's content but not the selected value. 'be.visible' only checks visibility.
Using aria-label ensures the locator is stable and accessible. ID selectors may change, and selecting by index or text content is fragile.
<select id="pets"> <option value="cat">Cat</option> <option value="doggo">Dog</option> <option value="bird">Bird</option> </select>
The select() command selects by visible text 'Dog', which exists. But the assertion checks for value 'dog', while the actual value is 'doggo'. This mismatch causes the test to fail.
Using cy.intercept() to wait for the API call ensures the dropdown options are loaded before selection. Fixed waits are unreliable, and selecting too early causes failures.