Below is a select control in my app:
<select id="answer">
<option value="yes"> Yes <option>
<option value="no"> No <option>
<option value="maybe"> Maybe <option>
</select>
One of the above values will always be selected by default when the page loads.
A problem I have is that I won't know what that default value will be each time.
Here is an example of the Cypress test I'm trying to write:
Given the select control is visible
When I select a different option
Then the selected option is updated
Here's what I am trying to do in pseudo-code:
cy.get('select').select(~~ any option that isn't the default value ~~)
Is it possible to write something like the above? I just want to update the selected option to something other than the default value (but I won't know that default value until during the test, as it will be random)
Example of how it would work during a test run:
- The page loads & the default selected option is 'No'
- Cypress should get the default selected value ('no')
- Then select an option that is not equal to 'no'
- Validate the selected option value is 'no'
Example of how the test might run a second time:
- The page loads & the default selected option is 'Maybe'
- Cypress should get the default selected value ('maybe')
- Then select an option that is not equal to 'maybe'
- Validate the selected option value is 'maybe'