UNPKG

@vibe/testkit

Version:
118 lines 6.66 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { test } from "@playwright/test"; /** * Presses a key on the page (e.g., Escape) * @param {Page} page - The Playwright page object * @param {string} key - The key to press (e.g., 'Escape', 'Enter') * @param {number} delay - The delay between each key press (default: 100) * @returns {Promise<void>} */ export const pressKey = (page_1, key_1, ...args_1) => __awaiter(void 0, [page_1, key_1, ...args_1], void 0, function* (page, key, delay = 100) { yield test.step(`Pressing key ${key}`, () => __awaiter(void 0, void 0, void 0, function* () { yield page.keyboard.press(key, { delay }); })); }); /** * Moves the mouse to the center of the element * @param {Page} page - The Playwright page object * @param {BoundingBox} boundingBox - The bounding box of the element to move to * @param {number} steps - The number of steps to take when moving (default: 1) * @returns {Promise<void>} */ export const mouseMove = (page_1, boundingBox_1, ...args_1) => __awaiter(void 0, [page_1, boundingBox_1, ...args_1], void 0, function* (page, boundingBox, steps = 1) { yield test.step(`Moving mouse to ${boundingBox.x}, ${boundingBox.y}`, () => __awaiter(void 0, void 0, void 0, function* () { yield page.mouse.move(boundingBox.x + boundingBox.width / 2, boundingBox.y + boundingBox.height / 2, { steps }); })); }); /** * Mouses down at the center of the element * @param {Page} page - The Playwright page object * @param {MouseButton} button - The mouse button to click (default: "left") * @param {number} clickCount - The number of clicks to perform (default: 1) * @returns {Promise<void>} */ export const mouseDown = (page_1, ...args_1) => __awaiter(void 0, [page_1, ...args_1], void 0, function* (page, button = "left", clickCount = 1) { yield test.step(`Mouse down ${button} ${clickCount} times`, () => __awaiter(void 0, void 0, void 0, function* () { yield page.mouse.down({ button, clickCount }); })); }); /** * Mouses up at the center of the element * @param {Page} page - The Playwright page object * @param {MouseButton} button - The mouse button to click (default: "left") * @param {number} clickCount - The number of clicks to perform (default: 1) * @returns {Promise<void>} */ export const mouseUp = (page_1, ...args_1) => __awaiter(void 0, [page_1, ...args_1], void 0, function* (page, button = "left", clickCount = 1) { yield test.step(`Mouse up ${button} ${clickCount} times`, () => __awaiter(void 0, void 0, void 0, function* () { yield page.mouse.up({ button, clickCount }); })); }); /** * Drags an element from one location and drops it to another * @param {Page} page - The Playwright page object * @param {Locator} sourceLocator - The locator of the element to drag * @param {Locator} targetLocator - The locator of the element to drop to * @param {number} steps - The number of steps to take when dragging (default: 5) * @returns {Promise<void>} */ export const dragAndDrop = (page_1, sourceLocator_1, targetLocator_1, ...args_1) => __awaiter(void 0, [page_1, sourceLocator_1, targetLocator_1, ...args_1], void 0, function* (page, sourceLocator, targetLocator, steps = 5) { yield test.step(`Dragging and dropping ${sourceLocator.toString()} to ${targetLocator.toString()}`, () => __awaiter(void 0, void 0, void 0, function* () { const sourceBox = yield sourceLocator.boundingBox(); const targetBox = yield targetLocator.boundingBox(); if (!sourceBox || !targetBox) { throw new Error("Source or target locator is not visible"); } yield mouseMove(page, sourceBox); yield mouseDown(page); yield mouseMove(page, targetBox, steps); yield mouseUp(page); })); }); /** * Scrolls the mouse wheel by a given number of pixels * @param {Page} page - The Playwright page object * @param {WheelScrollPixels} wheelScrollPixels - The number of pixels to scroll by * @returns {Promise<void>} */ export const mouseWheelScroll = (page, wheelScrollPixels) => __awaiter(void 0, void 0, void 0, function* () { yield test.step(`Scrolling ${wheelScrollPixels.deltaX}, ${wheelScrollPixels.deltaY}`, () => __awaiter(void 0, void 0, void 0, function* () { yield page.mouse.wheel(wheelScrollPixels.deltaX, wheelScrollPixels.deltaY); })); }); /** * Double clicks at the given coordinates * @param {Page} page - The Playwright page object * @param {Coordinates} coordinates - The coordinates to double click at * @param {MouseButton} button - The mouse button to click (default: "left") * @param {number} delay - The delay between each click (default: 100) * @returns {Promise<void>} */ export const mouseDoubleClick = (page_1, coordinates_1, ...args_1) => __awaiter(void 0, [page_1, coordinates_1, ...args_1], void 0, function* (page, coordinates, button = "left", delay = 100) { yield test.step(`Double clicking ${coordinates.x}, ${coordinates.y}`, () => __awaiter(void 0, void 0, void 0, function* () { yield page.mouse.dblclick(coordinates.x, coordinates.y, { button, delay }); })); }); /** * Clicks at the given coordinates * @param {Page} page - The Playwright page object * @param {Coordinates} coordinates - The coordinates to click at * @param {MouseButton} button - The mouse button to click (default: "left") * @param {number} delay - The delay between each click (default: 100) * @param {number} clickCount - The number of clicks to perform (default: 1) * @returns {Promise<void>} */ export const mouseClick = (page_1, coordinates_1, ...args_1) => __awaiter(void 0, [page_1, coordinates_1, ...args_1], void 0, function* (page, coordinates, button = "left", delay = 100, clickCount = 1) { yield test.step(`Clicking ${coordinates.x}, ${coordinates.y}`, () => __awaiter(void 0, void 0, void 0, function* () { yield page.mouse.click(coordinates.x, coordinates.y, { button, clickCount, delay }); })); }); //# sourceMappingURL=common-actions.js.map