0
0
Cypresstesting~5 mins

cy.select() for dropdowns in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of cy.select() in Cypress?

cy.select() is used to choose an option from a dropdown menu in a web page during automated testing.

Click to reveal answer
beginner
How do you select an option by its visible text using cy.select()?

You pass the visible text of the option as a string to select(). For example: cy.get('select').select('Option Text').

Click to reveal answer
intermediate
Can cy.select() select multiple options? If yes, how?

Yes, if the dropdown supports multiple selections, you can pass an array of option texts or values to select(). Example: cy.get('select').select(['Option1', 'Option2']).

Click to reveal answer
beginner
What happens if you try to select an option that does not exist using cy.select()?

Cypress will fail the test and show an error because it cannot find the option in the dropdown.

Click to reveal answer
intermediate
How can you verify that the correct option was selected after using cy.select()?

You can use cy.get('select').should('have.value', 'expectedValue') to check the selected option's value.

Click to reveal answer
Which command selects an option with visible text 'Apple' from a dropdown in Cypress?
Acy.get('select').choose('Apple')
Bcy.select('Apple')
Ccy.get('select').select('Apple')
Dcy.selectOption('Apple')
How do you select multiple options 'Red' and 'Blue' from a multi-select dropdown?
Acy.get('select').select('Red, Blue')
Bcy.get('select').choose(['Red', 'Blue'])
Ccy.get('select').select('Red').select('Blue')
Dcy.get('select').select(['Red', 'Blue'])
What will happen if you try to select an option that is not in the dropdown?
ACypress will throw an error and fail the test
BThe test will pass silently
CThe dropdown will select the first option
DThe test will skip the selection
Which assertion verifies the selected value in a dropdown after using cy.select()?
Acy.get('select').should('have.value', 'expectedValue')
Bcy.get('select').should('contain', 'value')
Ccy.get('select').should('be.visible')
Dcy.get('select').should('have.text', 'expectedValue')
What type of HTML element does cy.select() work with?
AButtons
BSelect dropdown elements
CInput text fields
DDiv containers
Explain how to use cy.select() to choose an option from a dropdown and verify the selection.
Think about finding the dropdown, selecting, then checking the result.
You got /3 concepts.
    Describe what happens if you try to select an option that does not exist in the dropdown using cy.select().
    Consider how Cypress handles invalid actions.
    You got /3 concepts.