UNPKG

playwright-cucumber-ts-steps

Version:

A collection of reusable Playwright step definitions for Cucumber in TypeScript, designed to streamline end-to-end testing across web, API, and mobile applications.

89 lines (88 loc) 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseClickOptions = parseClickOptions; exports.parseDblClickOptions = parseDblClickOptions; exports.parseHoverOptions = parseHoverOptions; exports.parseTypeOptions = parseTypeOptions; exports.parseFillOptions = parseFillOptions; exports.parseCheckOptions = parseCheckOptions; exports.parseUncheckOptions = parseUncheckOptions; exports.parseSelectOptions = parseSelectOptions; exports.parseGenericOptions = parseGenericOptions; exports.parseExpectOptions = parseExpectOptions; function parseClickOptions(table) { return parseGenericOptions(table); } function parseDblClickOptions(table) { return parseGenericOptions(table); } function parseHoverOptions(table) { return parseGenericOptions(table); } function parseTypeOptions(table) { return parseGenericOptions(table); } function parseFillOptions(table) { return parseGenericOptions(table); } function parseCheckOptions(table) { return parseGenericOptions(table); } function parseUncheckOptions(table) { return parseGenericOptions(table); } function parseSelectOptions(table) { return parseGenericOptions(table); } function parseGenericOptions(table) { if (!table) return {}; const options = {}; const rows = table.raw(); for (const [key, value] of rows) { switch (key) { case "timeout": case "delay": case "clickCount": options[key] = Number(value); break; case "force": case "noWaitAfter": case "strict": case "trial": options[key] = value === "true"; break; case "modifiers": options.modifiers = value.split(",").map((v) => v.trim()); break; case "button": if (["left", "middle", "right"].includes(value)) { options.button = value; } else { throw new Error(`Invalid button option: "${value}"`); } break; case "position": const [x, y] = value.split(",").map((n) => Number(n.trim())); if (isNaN(x) || isNaN(y)) { throw new Error(`Invalid position format: "${value}"`); } options.position = { x, y }; break; default: console.warn(`[⚠️ parseGenericOptions] Unknown option "${key}"`); break; } } return options; } function parseExpectOptions(table) { if (!table) return {}; const obj = Object.fromEntries(table.rows()); return { timeout: obj.timeout ? Number(obj.timeout) : undefined, log: obj.log === "true", }; }