Aller au contenu
CloudClick iOS

Gestures & keys

Taps, swipes, drags and pinches, plus hardware buttons and the keyboard. Coordinates can be points or 0–1 screen ratios; directional swipes re-randomise the start point, distance, angle and duration every time and follow a hand-like path.

Aperçu

  • ·The swipe family uses the W3C channel with human-like paths; the drag family uses WDA's native channel for better compatibility
  • ·Directional swipes avoid the screen edges by default; pass 'edge' when you want a system edge gesture such as swipe-back
  • ·Every duration is in seconds

client.click#

Tap at a coordinate; with a duration it holds for that many seconds before releasing (a long press).

typescript
client.click(x: number, y: number, duration?: number): object;

Paramètres

NomTypeObligatoirePar défautDescription
xnumberOui—Horizontal position: a 0–1 screen ratio, or points.
ynumberOui—Vertical position: a 0–1 screen ratio, or points.
durationnumberNon—Seconds to hold. Omit for a plain tap.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorRatio coordinates were given but the screen size could not be read (the WDA session is unhealthy).

Remarques

  • When x and y both fall between 0 and 1 they are screen ratios (0.5, 0.5 is the centre); otherwise they are points. The conversion needs the screen size and throws if it cannot be read.

Exemple

javascript
client.click(0.5, 0.5);        // 屏幕正中 / screen centre
client.click(200, 640);        // point
client.click(0.5, 0.9, 1.2);   // 长按 1.2 秒 / long press

Voir aussi client.tapHold、element.click

client.swipe#

Swipe from (x1, y1) to (x2, y2). The end points are exact; the path between them is hand-like — a slight random curve, slow then fast, with small jitter.

typescript
client.swipe(x1: number, y1: number, x2: number, y2: number, durationSec?: number): object;

Paramètres

NomTypeObligatoirePar défautDescription
x1numberOui—Start x.
y1numberOui—Start y.
x2numberOui—End x.
y2numberOui—End y.
durationSecnumberNon0Seconds from the start of the movement to lift-off. 0 picks a random duration based on the distance.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorRatio coordinates were given but the screen size could not be read (the WDA session is unhealthy).

Remarques

  • When x and y both fall between 0 and 1 they are screen ratios (0.5, 0.5 is the centre); otherwise they are points. The conversion needs the screen size and throws if it cannot be read.

Exemple

javascript
client.swipe(0.5, 0.8, 0.5, 0.2);        // 往上滑 / swipe up
client.swipe(0.5, 0.8, 0.5, 0.2, 0.6);   // 指定 0.6 秒 / take 0.6 seconds

Voir aussi client.swipeUp、client.drag

client.drag#

A native WDA drag from (x1, y1) to (x2, y2). The system generates the path and speed; in some apps (custom-drawn views, older iOS) it is more reliable than swipe.

typescript
client.drag(x1: number, y1: number, x2: number, y2: number, durationSec?: number): object;

Paramètres

NomTypeObligatoirePar défautDescription
x1numberOui—Start x.
y1numberOui—Start y.
x2numberOui—End x.
y2numberOui—End y.
durationSecnumberNon0Seconds to hold the start point before dragging — not the duration of the drag itself. 0 drags immediately.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorRatio coordinates were given but the screen size could not be read (the WDA session is unhealthy).

Remarques

  • When x and y both fall between 0 and 1 they are screen ratios (0.5, 0.5 is the centre); otherwise they are points. The conversion needs the screen size and throws if it cannot be read.

Exemple

javascript
client.drag(0.2, 0.5, 0.8, 0.5, 0.3);

Voir aussi client.swipe、client.dragUp

client.swipeUp#

Move the finger up (content moves up, revealing what is below). The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses the W3C gesture channel with a hand-like path: a slight random curve, slow then fast, with small jitter.

typescript
client.swipeUp(from?: "edge"): object;

Paramètres

NomTypeObligatoirePar défautDescription
from"edge"Non—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the bottom edge, which is the system's go-home gesture — rarely what you want.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Remarques

  • For the short, quick swipe from the lower screen used to scroll a feed, call client.swipeUpFromBottom(); swipeDownFromBottom, dragUpFromBottom and dragDownFromBottom are also available.

Exemple

javascript
client.swipeUp();

Voir aussi client.swipe

client.swipeDown#

Move the finger down (content moves down, revealing what is above). The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses the W3C gesture channel with a hand-like path: a slight random curve, slow then fast, with small jitter.

typescript
client.swipeDown(from?: "edge"): object;

Paramètres

NomTypeObligatoirePar défautDescription
from"edge"Non—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the top edge, which pulls down Notification Centre.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemple

javascript
client.swipeDown();

Voir aussi client.swipe

client.swipeLeft#

Move the finger from right to left. The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses the W3C gesture channel with a hand-like path: a slight random curve, slow then fast, with small jitter.

typescript
client.swipeLeft(from?: "edge"): object;

Paramètres

NomTypeObligatoirePar défautDescription
from"edge"Non—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the right edge.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemple

javascript
client.swipeLeft();

Voir aussi client.swipe

client.swipeRight#

Move the finger from left to right. The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses the W3C gesture channel with a hand-like path: a slight random curve, slow then fast, with small jitter.

typescript
client.swipeRight(from?: "edge"): object;

Paramètres

NomTypeObligatoirePar défautDescription
from"edge"Non—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the left edge, which is the system's swipe-back gesture.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemple

javascript
client.swipeRight();          // 普通右滑 / a normal swipe
client.swipeRight('edge');    // 返回上一页 / go back

Voir aussi client.swipe

client.dragUp#

Move the finger up (content moves up). The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses WDA's native drag channel and holds the start point for a random 0.05–0.2 seconds before moving. Switch to this family when swipe has no effect in an app.

typescript
client.dragUp(from?: "edge"): object;

Paramètres

NomTypeObligatoirePar défautDescription
from"edge"Non—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the bottom edge.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemple

javascript
client.dragUp();

Voir aussi client.drag

client.dragDown#

Move the finger down (content moves down). The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses WDA's native drag channel and holds the start point for a random 0.05–0.2 seconds before moving. Switch to this family when swipe has no effect in an app.

typescript
client.dragDown(from?: "edge"): object;

Paramètres

NomTypeObligatoirePar défautDescription
from"edge"Non—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the top edge.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemple

javascript
client.dragDown();

Voir aussi client.drag

client.dragLeft#

Move the finger from right to left. The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses WDA's native drag channel and holds the start point for a random 0.05–0.2 seconds before moving. Switch to this family when swipe has no effect in an app.

typescript
client.dragLeft(from?: "edge"): object;

Paramètres

NomTypeObligatoirePar défautDescription
from"edge"Non—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the right edge.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemple

javascript
client.dragLeft();

Voir aussi client.drag

client.dragRight#

Move the finger from left to right. The start point, distance (35–55% of the screen), angle (±5°) and duration are randomised every time, and by default the gesture stays at least 8% away from the screen edges so it never triggers a system edge gesture. Uses WDA's native drag channel and holds the start point for a random 0.05–0.2 seconds before moving. Switch to this family when swipe has no effect in an app.

typescript
client.dragRight(from?: "edge"): object;

Paramètres

NomTypeObligatoirePar défautDescription
from"edge"Non—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the left edge.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemple

javascript
client.dragRight();

Voir aussi client.drag

client.scroll#

Let WDA scroll the current screen in a direction. XCUITest computes the amount, which makes it more reliable than a swipe for lists and other scroll views.

typescript
client.scroll(direction: "up" | "down" | "left" | "right", distance?: number): object;

Paramètres

NomTypeObligatoirePar défautDescription
direction"up" | "down" | "left" | "right"Oui—The direction to scroll.
distancenumberNon1.0How far to scroll; 1.0 is roughly one screen.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exemple

javascript
client.scroll('down', 1.0);

Voir aussi client.swipeUp

client.pinch#

A two-finger pinch: a scale above 1 spreads the fingers (zoom in), below 1 pinches them together (zoom out).

typescript
client.pinch(scale: number, velocity?: number): object;

Paramètres

NomTypeObligatoirePar défautDescription
scalenumberOui—The scale factor.
velocitynumberNon1The speed; pass a negative value when pinching in (scale below 1).

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exemple

javascript
client.pinch(2, 1);      // 放大 / zoom in
client.pinch(0.5, -1);   // 缩小 / zoom out

client.hideKeyboard#

Dismiss the keyboard; client.isKeyboardShown() tells whether it is up.

typescript
client.hideKeyboard(): boolean;
client.isKeyboardShown(): boolean;

Valeur de retour

TypeDescription
booleanhideKeyboard: true once the keyboard is gone (also when it was never up); isKeyboardShown: true while the keyboard is visible.

Exemple

javascript
if (client.isKeyboardShown()) {
  client.hideKeyboard();
}

Voir aussi client.sendKeys

client.tapHold#

Press and hold at a point, then release (a long press).

typescript
client.tapHold(x: number, y: number, duration?: number): object;

Paramètres

NomTypeObligatoirePar défautDescription
xnumberOui—Horizontal position: a 0–1 screen ratio, or points.
ynumberOui—Vertical position: a 0–1 screen ratio, or points.
durationnumberNon1.0Seconds to hold.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
WDAErrorRatio coordinates were given but the screen size could not be read (the WDA session is unhealthy).

Remarques

  • When x and y both fall between 0 and 1 they are screen ratios (0.5, 0.5 is the centre); otherwise they are points. The conversion needs the screen size and throws if it cannot be read.

Exemple

javascript
client.tapHold(0.5, 0.5, 1.5);

Voir aussi client.click

client.home#

Go to the Home Screen.

typescript
client.home(): void;

Exemple

javascript
client.home();

Voir aussi client.press

client.press#

Press a hardware button: home, volumeUp or volumeDown.

typescript
client.press(name: "home" | "volumeUp" | "volumeDown"): object;

Paramètres

NomTypeObligatoirePar défautDescription
name"home" | "volumeUp" | "volumeDown"Oui—The button name.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exceptions

ExceptionLevée quand
ErrorThe name is not one of the three.

Exemple

javascript
client.press('volumeUp');

Voir aussi client.home

client.sendKeys#

Type into the focused text field, character by character through the keyboard. Tap the field first so it has focus.

typescript
client.sendKeys(value: string): object;

Paramètres

NomTypeObligatoirePar défautDescription
valuestringOui—The text to type; non-ASCII text is supported.

Valeur de retour

TypeDescription
objectThe raw WDA response; rarely needed.

Exemple

javascript
clickElement('accessibilityId', 'search_field', 5);
client.sendKeys('hello');

Voir aussi client.hideKeyboard、client.setClipboard

client.lock#

Lock the screen; client.unlock() unlocks it and client.locked() tells whether it is locked.

typescript
client.lock(): object;
client.unlock(): object;
client.locked(): boolean;

Valeur de retour

TypeDescription
object | booleanlock / unlock return the raw WDA response; locked returns true while the screen is locked.

Remarques

  • Unlocking only works on devices without a passcode.

Exemple

javascript
if (client.locked()) {
  client.unlock();
}