UNPKG

playwright-fluent

Version:
43 lines (42 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectOptionsInFocused = void 0; const handle_actions_1 = require("../../handle-actions"); const utils_1 = require("../../../utils"); const get_focused_handle_1 = require("../get-focused-handle"); async function selectOptionsInFocused(labels, page, options) { if (!page) { throw new Error(`Cannot select options '${labels}' because no browser has been launched`); } const waitOptions = { ...utils_1.defaultWaitUntilOptions, ...options, }; (0, utils_1.report)('waiting for a select element to have focus ...', options.verbose); await (0, utils_1.waitUntil)(async () => { const focusedHandle = await (0, get_focused_handle_1.getFocusedHandle)(page); if (focusedHandle === null) { return false; } const tagName = await focusedHandle.evaluate((el) => el.tagName); if (tagName && tagName === 'SELECT') { return true; } return false; }, async () => { const focusedHandle = await (0, get_focused_handle_1.getFocusedHandle)(page); if (focusedHandle === null) { return 'No element has the focus. You must first set the focus on a select element.'; } const tagName = await focusedHandle.evaluate((el) => el.tagName); if (tagName && tagName !== 'SELECT') { return `The element that has the focus is '${tagName}', but it should be a 'SELECT' element instead.`; } return 'never'; }, waitOptions); const handle = await (0, get_focused_handle_1.getFocusedHandle)(page); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const outerHtml = await handle.evaluate((el) => el.outerHTML); await (0, handle_actions_1.selectOptionsInHandle)(handle, outerHtml, labels, page, options); } exports.selectOptionsInFocused = selectOptionsInFocused;