playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Assertion to test the selected option of a select element is as expected

Open AndyGBC opened this issue 3 years ago • 0 comments

Can we have an assertion to check the selected option of a selement is as expected please?

Similar to asserting the value of an input field using .toHaveValue(foo) etc.

I would suggest:

await expect(page.locator('select[name=mySelect]').toHaveSelectedText('foo');
await expect(page.locator('select[name=mySelect]').toHaveSelectedValue('foo123');

Where the html is:

<select name='mySelect'>
  <option value='foo123'>foo</option>
  <option value='bar123'>bar</option>
  <option value='baz123'>baz</option>
</select>

and I have selected the first option and saved, then returned to the page to check the values saved correctly.

I have seen the following on this but really don't like using eval if an assertion method is available. https://github.com/microsoft/playwright/issues/7645

AndyGBC avatar Sep 21 '22 15:09 AndyGBC