appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
267 lines • 17.5 kB
TypeScript
import type { XCUITestDriver } from '../driver';
import type { ActionSequence, Element } from '@appium/types';
import type { Direction } from './types';
/**
* Shakes the device.
*
* @group Simulator Only
* @throws {Error} If called on a real device
*/
export declare function mobileShake(this: XCUITestDriver): Promise<void>;
/**
* Clicks on an element.
*
* In web context, uses native web tap if configured, otherwise uses atom-based clicking.
* In native context, delegates to native click.
*/
export declare function click(this: XCUITestDriver, el: Element | string): Promise<void>;
/**
* Releases all actions.
*
* On this platform, this is a no-op.
*/
export declare function releaseActions(this: XCUITestDriver): Promise<void>;
/**
* Performs a sequence of W3C actions.
*
* Automatically converts MOUSE pointer type to TOUCH and filters out zero-duration pauses.
*
* @param actions - Array of action sequences to perform
* @throws {errors.InvalidArgumentError} If actions contain web elements
*/
export declare function performActions(this: XCUITestDriver, actions: ActionSequence[]): Promise<void>;
/**
* Performs a native click on an element.
*
* @param el - Element to click
* @group Native Only
*/
export declare function nativeClick(this: XCUITestDriver, el: Element | string): Promise<void>;
/**
* Scrolls the current viewport to the given element.
*
* This command expects the destination element to be inside a scrollable container and is hittable. The scroll direction is detected automatically.
*
* This API uses native XCTest calls, so it is performant. The same native call is implicitly performed by a `click` command if the destination element is outside the current viewport.
*
* @since 4.7.0
* @param elementId - The internal element identifier (as hexadecimal hash string) to scroll to. The destination element must be located in a scrollable container and must be hittable. If the element is already present in the current viewport then no action is performed.
* @throws {errors.InvalidArgumentError} If elementId is not provided
* @privateRemarks See https://github.com/facebook/WebDriverAgent/blob/master/WebDriverAgentLib/Commands/FBElementCommands.m for details on WDA gestures API
*/
export declare function mobileScrollToElement(this: XCUITestDriver, elementId: Element | string): Promise<void>;
/**
* Scrolls an element or the entire screen.
*
* Use this command to emulate precise scrolling in tables or collection views where it is already known to which element the scrolling should be performed.
*
* The arguments define the chosen strategy: one of `name`, `direction`, `predicateString` or `toVisible`.
*
* **All strategies are exclusive**; only one strategy can be used at one time.
*
* **Known Limitations:**
*
* - If it is necessary to perform many scroll gestures on parent container to reach the necessary child element (tens of them), then the method call may fail. *
* - The implementation of this extension relies on several undocumented XCTest features, which might not always be reliable.
*
* @param name - The internal element identifier (as hexadecimal hash string) to scroll on (e.g. the container). The Application element will be used if this argument is not provided.
* @param direction - The main difference between this command and a `mobile: swipe` command using the same direction is that `mobile: scroll` will attempt to move the current viewport exactly to the next or previous page (the term "page" means the content, which fits into a single device screen).
* @param predicateString - The `NSPredicate` locator of the child element, to which the scrolling should be performed. Has no effect if `elementId` is not a container.
* @param toVisible - If `true`, scrolls to the first visible `elementId` in the parent container. Has no effect if `elementId` is unset.
* @param distance - A ratio of the screen height; `1.0` means a full-screen-worth of scrolling.
* @param elementId - Element ID or Element used in various strategies.
* @throws {errors.InvalidArgumentError} If no valid strategy is provided or if direction is invalid
* @example
* ```python
* driver.execute_script('mobile: scroll', {'direction': 'down'})
* ```
*/
export declare function mobileScroll(this: XCUITestDriver, name?: string, direction?: Direction, predicateString?: string, toVisible?: boolean, distance?: number, elementId?: Element | string): Promise<void>;
/**
* Performs a swipe gesture in the specified direction.
*
* @param direction - Direction to swipe ('up', 'down', 'left', or 'right')
* @param velocity - Optional velocity of the swipe
* @param elementId - Optional element to swipe on. If not provided, swipes on the application element
* @throws {errors.InvalidArgumentError} If direction is invalid
*/
export declare function mobileSwipe(this: XCUITestDriver, direction: Direction, velocity?: number, elementId?: Element | string): Promise<void>;
/**
* Performs a pinch gesture on the given element or on the Application element.
*
* @param scale - Pinch scale (float value). A value between `0` and `1` performs a "pinch close" (or "zoom out"); a value greater than `1` performs a "pinch open" ("zoom in").
* @param velocity - The velocity of the pinch in scale factor per second (float value).
* @param elementId - The internal element identifier (as hexadecimal hash string) to pinch on. The Application element will be used if this parameter is not provided.
* @see https://developer.apple.com/documentation/xctest/xcuielement/1618669-pinchwithscale?language=objc
* @example
*
* ```ruby
* execute_script 'mobile: pinch', scale: 0.5, velocity: 1.1, element: element.ref
* ```
*/
export declare function mobilePinch(this: XCUITestDriver, scale: number, velocity: number, elementId?: Element | string): Promise<void>;
/**
* Performs double tap gesture on the given element or on the screen.
*
* @param elementId - The internal element identifier (as hexadecimal hash string) to double tap on. The Application element will be used if this parameter is not provided.
* @param x - The _x_ coordinate (float value) to double tap on.
* @param y - The _y_ coordinate (float value) to double tap on.
* @example
* ```javascript
* // using WebdriverIO
* await driver.execute('mobile: doubleTap', {element: element.value.ELEMENT});
* ```
*/
export declare function mobileDoubleTap(this: XCUITestDriver, elementId?: Element | string, x?: number, y?: number): Promise<void>;
/**
* Performs two finger tap gesture on the given element or on the application element.
*
* @param elementId - The internal element identifier (as hexadecimal hash string) to double tap on. The Application element will be used if this parameter is not provided.
* @see https://developer.apple.com/documentation/xctest/xcuielement/1618675-twofingertap?language=objc
* @example
* ```csharp
* Dictionary<string, object> tfTap = new Dictionary<string, object>();
* tfTap.Add("element", element.Id);
* ((IJavaScriptExecutor)driver).ExecuteScript("mobile: twoFingerTap", tfTap);
* ```
*/
export declare function mobileTwoFingerTap(this: XCUITestDriver, elementId?: Element | string): Promise<void>;
/**
* Performs a "long press" gesture on the given element or on the screen.
*
* @param duration - The duration (in seconds) of the gesture.
* @param x - The _x_ coordinate (float value) to hold on.
* @param y - The _y_ coordinate (float value) to hold on.
* @param elementId - The internal element identifier (as hexadecimal hash string) to hold on. The Application element will be used if this parameter is not provided.
* @see https://developer.apple.com/documentation/xctest/xcuielement/1618663-pressforduration?language=objc
* @example
* ```csharp
* Dictionary<string, object> tfLongTap = new Dictionary<string, object>();
* tfLongTap.Add("element", element.Id);
* tfLongTap.Add("duration", 2.0);
* ((IJavaScriptExecutor)driver).ExecuteScript("mobile: touchAndHold", tfLongTap);
* ```
*/
export declare function mobileTouchAndHold(this: XCUITestDriver, duration: number, x?: number, y?: number, elementId?: Element | string): Promise<void>;
/**
* Performs tap gesture by coordinates on the given element or on the screen.
*
* @param x - The _x_ coordinate (float value) to tap on. If `elementId` is provided, this is computed relative to the element; otherwise it is computed relative to the active Application element.
* @param y - The _y_ coordinate (float value) to tap on. If `elementId` is provided, this is computed relative to the element; otherwise it is computed relative to the active Application element.
* @param elementId - The internal element identifier (as hexadecimal hash string) to tap on. The Application element will be used if this parameter is not provided.
*/
export declare function mobileTap(this: XCUITestDriver, x: number, y: number, elementId?: string | Element): Promise<void>;
/**
* Performs drag and drop gesture by coordinates on the given element or on the screen.
*
* @param duration - The duration (in seconds) of the gesture. Must be between `0.5` and `60.0`, inclusive.
* @param fromX - The _x_ coordinate (float value) of the starting drag point.
* @param fromY - The _y_ coordinate (float value) of the starting drag point.
* @param toX - The _x_ coordinate (float value) of the ending drag point.
* @param toY - The _y_ coordinate (float value) of the ending drag point.
* @param elementId - The internal element identifier (as hexadecimal hash string) to drag. If provided, all coordinates will be calculated relative to this element; otherwise they will be calculated relative to the active Application element.
* @see https://developer.apple.com/documentation/xcuiautomation/xcuicoordinate/press(forduration:thendragto:)?language=objc
* @example
* ```java
* JavascriptExecutor js = (JavascriptExecutor) driver;
* Map<String, Object> params = new HashMap<>();
* params.put("duration", 1.0);
* params.put("fromX", 100);
* params.put("fromY", 100);
* params.put("toX", 200);
* params.put("toY", 200);
* params.put("element", ((RemoteWebElement) element).getId());
* js.executeScript("mobile: dragFromToForDuration", params);
* ```
*/
export declare function mobileDragFromToForDuration(this: XCUITestDriver, duration: number, fromX: number, fromY: number, toX: number, toY: number, elementId?: string | Element): Promise<void>;
/**
* Initiates a press-and-hold gesture, drags to another coordinate or an element with a given velocity, and holds for a given duration.
*
* @param pressDuration - The duration (in seconds) of the press-and-hold gesture at the starting point. Must be between `0.5` and `60.0`, inclusive.
* @param holdDuration - The duration (in seconds) of the hold gesture at the ending point (after dragging). Must be between `0.5` and `60.0`, inclusive.
* @param velocity - The speed (in pixels-per-second) which to move from the initial position to the end position.
* @param fromElementId - The internal element identifier (as hexadecimal hash string) to drag from. Absolute screen coordinates are expected if this argument is not provided.
* @param toElementId - The internal element identifier (as hexadecimal hash string) to drag to. Absolute screen coordinates are expected if this argument is not provided.
* @param fromX - The _x_ coordinate (float value) of the starting drag point.
* @param fromY - The _y_ coordinate (float value) of the starting drag point.
* @param toX - The _x_ coordinate (float value) of the ending drag point.
* @param toY - The _y_ coordinate (float value) of the ending drag point.
* @throws {errors.InvalidArgumentError} If toElementId is missing when fromElementId is provided, or if coordinates are missing when fromElementId is not provided
* @see https://developer.apple.com/documentation/xctest/xcuielement/3551693-pressforduration?language=objc
* @see https://developer.apple.com/documentation/xctest/xcuicoordinate/3551692-pressforduration?language=objc
*/
export declare function mobileDragFromToWithVelocity(this: XCUITestDriver, pressDuration: number, holdDuration: number, velocity: number, fromElementId?: Element | string, toElementId?: Element | string, fromX?: number, fromY?: number, toX?: number, toY?: number): Promise<void>;
/**
* Sends one or more taps with one or more touch points.
*
* @since 1.17.1
* @param numberOfTaps - Number of taps to perform.
* @param numberOfTouches - Number of touch points to use.
* @param elementId - The internal element identifier (as hexadecimal hash string) to perform one or more taps. The Application element will be used if this parameter is not provided.
* @see https://developer.apple.com/documentation/xctest/xcuielement/1618671-tapwithnumberoftaps?language=objc
* @example
* ```ruby
* e = @driver.find_element :id, 'target element'
* # Taps the element with a single touch point twice
* @driver.execute_script 'mobile: tapWithNumberOfTaps', {element: e.ref, numberOfTaps: 2, numberOfTouches: 1}
* ```
*/
export declare function mobileTapWithNumberOfTaps(this: XCUITestDriver, numberOfTouches?: number, numberOfTaps?: number, elementId?: Element | string | undefined): Promise<void>;
/**
* Performs a "force press" on the given element or coordinates.
*
* @throws If the target device does not support the "force press" gesture.
* @param x - The _x_ coordinate of the gesture. If `elementId` is set, this is calculated relative to its position; otherwise it's calculated relative to the active Application.
* @param y - The _y_ coordinate of the gesture. If `elementId` is set, this is calculated relative to its position; otherwise it's calculated relative to the active Application.
* @param duration - The duration (in seconds) of the force press. If this is provided, `pressure` must also be provided.
* @param pressure - A float value defining the pressure of the force press. If this is provided, `duration` must also be provided.
* @param elementId - The internal element identifier (as hexadecimal hash string) to perform one or more taps. The Application element will be used if this parameter is not provided.
* @throws {Error} If the target device does not support the "force press" gesture
*/
export declare function mobileForcePress(this: XCUITestDriver, x?: number, y?: number, duration?: number, pressure?: number, elementId?: Element | string): Promise<void>;
/**
* Performs selection of the next or previous picker wheel value.
*
* This might be useful if these values are populated dynamically; you don't know which one to select, or the value selection using the `sendKeys` API does not work (for whatever reason).
*
* @throws Upon failure to change the current picker value.
* @param elementId - `PickerWheel`'s internal element ID as hexadecimal hash string. Value selection will be performed on this element. This element must be of type `XCUIElementTypePickerWheel`.
* @param order - Either `next` to select the value _next_ to the current from the target picker wheel, or `previous` to select the _previous_ value.
* @param offset - The value in range `[0.01, 0.5]`. It defines how far from picker wheel's center the click should happen. The actual distance is calculated by multiplying this value to the actual picker wheel height. Too small an offset value may not change the picker wheel value at all, and too high a value may cause the wheel to switch two or more values at once. Usually the optimal value is located in range `[0.15, 0.3]`.
* @param value - If provided WDA will try to automatically scroll in the given direction until the actual picker value reaches the expected one or the amount of scrolling attempts is exceeded.
* @param maxAttempts - The maximum number of scrolling attempts to reach `value` before an error will be thrown. Only makes sense in combination with `value`.
* @throws {errors.InvalidArgumentError} If elementId is not provided or if order is invalid
* @example
* ```java
* JavascriptExecutor js = (JavascriptExecutor) driver;
* Map<String, Object> params = new HashMap<>();
* params.put("order", "next");
* params.put("offset", 0.15);
* params.put("element", ((RemoteWebElement) element).getId());
* js.executeScript("mobile: selectPickerWheelValue", params);
* ```
*/
export declare function mobileSelectPickerWheelValue(this: XCUITestDriver, elementId: Element | string, order: string, offset?: number, value?: string, maxAttempts?: number): Promise<void>;
/**
* Performs a rotate gesture on the given element.
*
* @see https://developer.apple.com/documentation/xctest/xcuielement/1618665-rotate?language=objc
* @param rotation - The rotation gesture (in radians)
* @param velocity - The velocity (in radians-per-second) of the gesture.
* @param elementId - The internal element identifier (as hexadecimal hash string) to perform the gesture on.
* The Application element will be used if this parameter is not provided.
* @example
* ```java
* JavascriptExecutor js = (JavascriptExecutor) driver;
* js.executeScript("mobile: rotateElement", ImmutableMap.of(
* // rotate clockwise, 90 degrees
* "rotation", -Math.PI / 2,
* // in approximately two seconds
* "velocity", Math.PI / 4,
* "element", ((RemoteWebElement) element).getId()
* ));
* ```
*/
export declare function mobileRotateElement(this: XCUITestDriver, rotation: number, velocity: number, elementId?: Element | string): Promise<void>;
//# sourceMappingURL=gesture.d.ts.map