rob-balfre / svelte-select

Svelte Select. A select component for Svelte
https://svelte-select-examples.vercel.app
Other
1.25k stars 175 forks source link

How to select an item via playwright testing? #621

Closed josephceth closed 10 months ago

josephceth commented 10 months ago

Pretty straight forward issue, I am struggling with setting the value of a svelte-select component for our playwright testing, whether through writing my own code or using the recording, the results are inconsistent.

We've tried:

await page.locator('label').filter({ hasText: 'Default Value' }).getByRole('textbox').click()
await page.getByText('Value to Select, { exact: true }).click() 

...in an attempt to open the control and select an item, but again, it doesn't work all the time.

Any help would be appreciated...thanks!

rob-balfre commented 10 months ago

@josephceth sure, I've tackled it like this in the past:

await page.locator('input[id=<ID OF SELECT>]').fill('<FILTER TEXT>');
await page.click('.svelte-select-list .list-item >> nth=0'); // or something similar to match your need
rob-balfre commented 10 months ago

Or

await page.locator('input[id=<ID OF SELECT>]').click();
await page.click('.svelte-select-list .list-item >> nth=1'); // or something similar to match your need
josephceth commented 10 months ago

Welp...I feel dumb, the svelte-select was a piece of a much large component and the id wasn't being applied to the select it was applied to the hidden input containing the value.

As if by magic, once an Id was provided to the actual