Pular para o conteúdo
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.

Visão geral

  • ·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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
xnumberSim—Horizontal position: a 0–1 screen ratio, or points.
ynumberSim—Vertical position: a 0–1 screen ratio, or points.
durationnumberNão—Seconds to hold. Omit for a plain tap.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorRatio coordinates were given but the screen size could not be read (the WDA session is unhealthy).

Observações

  • 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.

Exemplo

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

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
x1numberSim—Start x.
y1numberSim—Start y.
x2numberSim—End x.
y2numberSim—End y.
durationSecnumberNão0Seconds from the start of the movement to lift-off. 0 picks a random duration based on the distance.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorRatio coordinates were given but the screen size could not be read (the WDA session is unhealthy).

Observações

  • 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.

Exemplo

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

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
x1numberSim—Start x.
y1numberSim—Start y.
x2numberSim—End x.
y2numberSim—End y.
durationSecnumberNão0Seconds to hold the start point before dragging — not the duration of the drag itself. 0 drags immediately.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorRatio coordinates were given but the screen size could not be read (the WDA session is unhealthy).

Observações

  • 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.

Exemplo

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

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
from"edge"Não—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.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Observações

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

Exemplo

javascript
client.swipeUp();

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
from"edge"Não—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the top edge, which pulls down Notification Centre.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemplo

javascript
client.swipeDown();

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
from"edge"Não—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the right edge.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemplo

javascript
client.swipeLeft();

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
from"edge"Não—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.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemplo

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

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
from"edge"Não—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the bottom edge.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemplo

javascript
client.dragUp();

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
from"edge"Não—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the top edge.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemplo

javascript
client.dragDown();

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
from"edge"Não—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the right edge.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemplo

javascript
client.dragLeft();

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
from"edge"Não—Omit it for a normal swipe; pass 'edge' to start at the screen edge: starts at the left edge.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorINVALID_ARGUMENTThe argument is neither omitted nor 'edge' (for example an old-style { fromEdge: true }).

Exemplo

javascript
client.dragRight();

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
direction"up" | "down" | "left" | "right"Sim—The direction to scroll.
distancenumberNão1.0How far to scroll; 1.0 is roughly one screen.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exemplo

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

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
scalenumberSim—The scale factor.
velocitynumberNão1The speed; pass a negative value when pinching in (scale below 1).

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exemplo

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;

Valor de retorno

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

Exemplo

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

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
xnumberSim—Horizontal position: a 0–1 screen ratio, or points.
ynumberSim—Vertical position: a 0–1 screen ratio, or points.
durationnumberNão1.0Seconds to hold.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
WDAErrorRatio coordinates were given but the screen size could not be read (the WDA session is unhealthy).

Observações

  • 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.

Exemplo

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

Veja também client.click

client.home#

Go to the Home Screen.

typescript
client.home(): void;

Exemplo

javascript
client.home();

Veja também client.press

client.press#

Press a hardware button: home, volumeUp or volumeDown.

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

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
name"home" | "volumeUp" | "volumeDown"Sim—The button name.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exceções

ExceçãoLançada quando
ErrorThe name is not one of the three.

Exemplo

javascript
client.press('volumeUp');

Veja também 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;

Parâmetros

NomeTipoObrigatórioPadrãoDescrição
valuestringSim—The text to type; non-ASCII text is supported.

Valor de retorno

TipoDescrição
objectThe raw WDA response; rarely needed.

Exemplo

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

Veja também 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;

Valor de retorno

TipoDescrição
object | booleanlock / unlock return the raw WDA response; locked returns true while the screen is locked.

Observações

  • Unlocking only works on devices without a passcode.

Exemplo

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