I’m testing my django server front-end with cypress. I should test the case where user selects empty string from options list. The code
//Next try to remove frequency
cy.get('select').eq(5).find('option').contains('').then((selectOption) => {
cy.get('select').eq(5).select(selectOption.text());
});
led to error message:
cy.contains() cannot be passed an empty string
although the empty string belongs to my choices:
html:
<select id="id_update_freq" calss ="form-control" name="update_freq"
<option value="">""</option>
<option value="vk">Viikkotilasto</option>
<option value="kk">Kuukausitilasto</option>
<option value="nv">Kolmannesvuositilasto</option>
<option value="kv">Puolivuositilasto</option>
<option value="pv">Vuositilasto</option>
</select>
How can I test the case ?
2
Answers
You should use
select()
:One problem you have is the HTML has no
<option>
with empty string. The first option is the one you try to select, but it has two quotes in the string, so it’s not technically empty.So in your test this will pass
But after fixing the typo,
you can then select the empty option by using RegExp in the
.contains()
commandOf course,
cy.select()
works too :).