UNPKG

@sap_oss/wdio-qmate-service

Version:

[![REUSE status](https://api.reuse.software/badge/github.com/SAP/wdio-qmate-service)](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[![Node.js CI](https://github.com/SAP/wdio-qmate-service/actions/workflows/node.js.yml/badge.svg)](http

86 lines 3.99 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Gestures = void 0; const verboseLogger_1 = require("../../helper/verboseLogger"); const errorHandler_1 = __importDefault(require("../../helper/errorHandler")); /** * @class gestures * @memberof mobile */ class Gestures { vlf = new verboseLogger_1.VerboseLoggerFactory("mobile", "gestures"); ErrorHandler = new errorHandler_1.default(); /** * @function swipe * @memberof mobile.gestures * @description Swipe from one point to another on the screen, * Ensure that the provided coordinates are within the bounds of the screen to avoid unexpected behavior. * @param {number} startX - The starting X coordinate of the swipe * @param {number} startY - The starting Y coordinate of the swipe * @param {number} endX - The ending X coordinate of the swipe * @param {number} endY - The ending Y coordinate of the swipe * @param {number} [duration=1000] - The duration of the swipe in milliseconds (optional, default is 1000ms) * @returns {Promise<void>} * @example * // Swipes from left to right across the screen horizontally (useful for image carousels or galleries). * await mobile.gestures.swipe(100, 800, 800, 800); * // Swipes from bottom to top vertically to scroll down a list. * await mobile.gestures.swipe(300, 1000, 300, 400); * // Swipes from the top down to refresh content on a mobile app (common for pull-to-refresh). * await mobile.gestures.swipe(400, 200, 400, 800); */ async swipe(startX, startY, endX, endY, duration = 1000) { const vl = this.vlf.initLog(this.swipe); try { // Validate input coordinates if (startX < 0 || startY < 0 || endX < 0 || endY < 0) { throw new Error(`Invalid coordinates: (${startX}, ${startY}) to (${endX}, ${endY}) must be non-negative.`); } // Log the swipe action for debugging vl.log(`Swiping from (${startX}, ${startY}) to (${endX}, ${endY}) over ${duration}ms`); await browser.touchPerform([ { action: "press", options: { x: startX, y: startY } }, { action: "wait", options: { ms: duration } }, // Wait for the duration of the swipe { action: "moveTo", options: { x: endX, y: endY } }, { action: "release" } ]); vl.log("Swipe completed successfully..."); } catch (error) { this.ErrorHandler.logException(error); } } /** * @function tap * @memberof mobile.gestures * @description Executes a tap at the given screen coordinates, * Ensure that the provided coordinates are within the bounds of the screen to avoid unexpected behavior. * @param {number} coordX - The horizontal screen coordinate for the tap. * @param {number} coordY - The vertical screen coordinate for the tap. * @returns {Promise<void>} * @example * await mobile.gestures.tap(100, 800); */ async tap(coordX, coordY) { const vl = this.vlf.initLog(this.tap); try { // Input validation if (coordX < 0 || coordY < 0) { throw new Error(`Invalid coordinates: x (${coordX}) and y (${coordY}) must be non-negative.`); } // Log the tap action for debugging vl.log(`Initiating tap at coordinates (${coordX}, ${coordY}).`); await browser.touchPerform([{ action: "tap", options: { coordX, coordY } }]); vl.log("Coordinate tap completed successfully..."); } catch (error) { this.ErrorHandler.logException(error); } } } exports.Gestures = Gestures; exports.default = new Gestures(); //# sourceMappingURL=gestures.js.map