UNPKG

tm-playwright-framework

Version:

Playwright Cucumber TS framework - The easiest way to learn

142 lines (141 loc) 7.46 kB
/** * MOUSE.TS * * This TypeScript file contains methods to perform mouse actions. * * @author Sasitharan, Govindharam * @reviewer Sahoo, AshokKumar * @version 1.0 - 1st-JUNE-2025 * * @methods * - `singleClick`: Accepts an element locator as a `string` or Element and performs a left-click action. Based on boolean value force click will be performed. * - `doubleClick`: Accepts an element locator as a `string` or Element and performs a left double-click action. Based on boolean value force click will be performed. * - `rightClick`: Accepts an element locator as a `string` or Element and performs a right-click action. Based on boolean value force click will be performed. * - `shiftClick`: Accepts an element locator as a `string` or Element and performs a Shift + Left-click action. * - `ctrlClick`: Accepts an element locator as a `string` or Element and performs a Control + Left-click action. * - `hoverOver`: Accepts an element locator as a `string` or Element and performs a mouse hover action. * - `clickAt`: Accepts an element locator as a `string` or Element and performs a left-click at the given coordinates. * - `scrollBy`: Accepts an element locator as a `string` or Element and performs a vertical scroll based on a given positive or negative value. * - `scroll`: Accepts x and y axis coordinates and scroll * - `clickButtonAndWait`: Accepts an element locator as a `string` or Element , performs a click action, and waits for the page load to complete. * - `dragAndDrop`: Accepts an element locator as a `string` or Element and performs a drag-and-drop operation from a source element to a target element. * - `dragAndDropByCoordinates`: Accepts an element locator as a `string` or Element and performs a drag-and-drop action from a source element to a target using coordinates. */ import { Page } from "@playwright/test"; export default class MouseAction { private page; constructor(page: Page); /** * Performs a single left-click action on the specified element. * @param {any} locator - The element locator as a string or Element. * @param {boolean} [forceClick=false] - (Optional) Whether to force the click action. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ singleClick(locator: any, options?: { forceClick?: boolean; timeOut?: number; }): Promise<void>; /** * Performs a double left-click action on the specified element. * @param {any} locator - The element locator as a string or Element. * @param {boolean} [forceClick=false] - (Optional) Whether to force the double-click action. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ doubleClick(locator: any, options?: { forceClick?: boolean; timeOut?: number; }): Promise<void>; /** * Performs a right-click action on the specified element. * @param {any} locator - The element locator as a string or Element. * @param {boolean} [forceClick=false] - (Optional) Whether to force the right-click action. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ rightClick(locator: any, options?: { forceClick?: boolean; timeOut?: number; }): Promise<void>; /** * Performs a Shift + Left-click action on the specified element. * @param {any} locator - The element locator as a string or Element. * @param {boolean} [forceClick=false] - (Optional) Whether to force the click action. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ shiftClick(locator: any, options?: { forceClick?: boolean; timeOut?: number; }): Promise<void>; /** * Performs a Control + Left-click action on the specified element. * @param {any} locator - The element locator as a string or Element. * @param {boolean} [forceClick=false] - (Optional) Whether to force the click action. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ ctrlClick(locator: any, options?: { forceClick?: boolean; timeOut?: number; }): Promise<void>; /** * Performs a mouse hover action on the specified element. * @param {any} locator - The element locator as a string or Element. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ hoverOver(locator: any, options?: { timeOut?: number; }): Promise<void>; /** * Performs a left-click action at the specified coordinates on the element. * @param {any} locator - The element locator as a string or Element. * @param {number} x_axis - The x-coordinate for the click. * @param {number} y_axis - The y-coordinate for the click. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ clickAt(locator: any, x_axis: number, y_axis: number, timeOut?: number): Promise<void>; /** * Performs a vertical scroll on the specified element by a given value. * @param {string} locator - The element locator as a string. * @param {number} scrollTop - The amount to scroll vertically (positive or negative). * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ scrollBy(locator: string, scrollTop: number, timeOut?: number): Promise<void>; /** * Scrolls the page to the specified x and y coordinates. * @param {number} x_axis - The x-coordinate to scroll to. * @param {number} y_axis - The y-coordinate to scroll to. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ scroll(x_axis: number, y_axis: number, timeOut?: number): Promise<void>; /** * Performs a click action on the specified element and waits for the page to load completely. * @param {any} locator - The element locator as a string or Element. * @param {number} [timeOut=30000] - (Optional) Timeout in milliseconds. * @returns {Promise<void>} */ clickButtonAndWait(locator: any, timeOut?: number): Promise<void>; /** * Performs a drag-and-drop operation from a source element to a target element. * @param {any} sourceLocator - The element locator (string or Locator) to drag. * @param {any} targetLocator - The element locator (string or Locator) to drop onto. * @param {number} [timeOut=30000] - Optional timeout in milliseconds. * @returns {Promise<void>} */ dragAndDrop(sourceLocator: any, targetLocator: any, timeOut?: number): Promise<void>; /** * Performs a drag-and-drop action from a source element to a target using coordinates. * @param {any} sourceLocator - The locator (string or Locator) for the element to drag. * @param {number} offsetX - X offset from the source element's center. * @param {number} offsetY - Y offset from the source element's center. * @param {number} [timeOut=30000] - Optional timeout in milliseconds. * @returns {Promise<void>} */ dragAndDropByCoordinates(sourceLocator: any, offsetX: number, offsetY: number, timeOut?: number): Promise<void>; }