UNPKG

e2ed

Version:

E2E testing framework over Playwright

21 lines (20 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectText = void 0; const step_1 = require("../step"); /** * Selects text in input elements. */ const selectText = (selector, start = 0, end, options) => (0, step_1.step)(`Select text in input element, from ${start} to ${end ?? 'the end'}`, async () => { await selector.getPlaywrightLocator().evaluate((element, { clientEnd, clientStart }) => { if (!(element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement)) { throw new Error('selectText works only with input or textarea'); } const valueLength = element.value.length; const selectionStart = clientStart ?? 0; const selectionEnd = clientEnd ?? valueLength; element.focus(); element.setSelectionRange(selectionStart, selectionEnd); }, { clientEnd: end, clientStart: start }, options); }, { payload: { end, ...options, selector, start }, type: 5 /* LogEventType.InternalAction */ }); exports.selectText = selectText;