Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pablocattaneo/fd062f884b3c31eda5e8ee248f03f79c to your computer and use it in GitHub Desktop.

Select an option

Save pablocattaneo/fd062f884b3c31eda5e8ee248f03f79c to your computer and use it in GitHub Desktop.
test("Dropdown should be sorted in alphabetical order", async ({ page }) => {
await page.goto(PAGE_URL);
const dropdown = page.getByRole("combobox").and(page.locator("#country"));
const options = await dropdown.locator("option").all();
const optionValues = await Promise.all(options.map(option => option.textContent()));
const sortedOptionValues = [...optionValues].sort();
expect(optionValues).toEqual(sortedOptionValues);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment