B2D-Ventures/tests/helpers/dropdownUtils.ts
Nantawat Sukrisunt 65ad1e2661 test setup update
2024-11-10 19:06:02 +07:00

25 lines
881 B
TypeScript

import { Page, Locator } from '@playwright/test';
export const selectFirstOption = async (page: Page, triggerLocator: Locator) => {
let selected = false
while (!selected) {
try {
await triggerLocator.click({ force: true });
// Select the first available option
const firstOption = page.getByRole("option").first();
await firstOption.waitFor({ state: 'visible', timeout: 1000 });
// Retrieve and log the text content of the first option
const optionText = await firstOption.textContent();
console.log(`${optionText}`);
await firstOption.click();
console.log("Selected.");
selected = true
} catch (error) {
console.log("Retrying as the combobox disappeared.");
await page.waitForTimeout(100);
}
}
};