Gestures for maps and canvases (doubleTap, pinchIn, pinchOut, gesture, hold)

in Japanese(日本語)

Multi-touch gestures: double tap, pinch to zoom out, pinch to zoom in, and a raw multi-finger gesture builder for anything those three cannot express.

Functions

function description
doubleTap(sel?, settle:, waitSeconds:) / doubleTap(x:y:settle:) Double taps. Omitting the selector taps the center of the screen. Writing tap twice does not substitute for it — the round trip exceeds the OS's double-tap detection window. On Android with gesture navigation, an element whose centre lies inside the band at the bottom edge of the screen is double-tapped on its part above the band (see tap). The x:y: form double taps raw coordinates (same system as tap(x:y:): iOS = pt, Android = px; returns nothing; the point is used as given) — prefer a selector whenever one is available.
pinchOut(sel?, scale: 2.0, durationSeconds: 0.5, maxGestureSeconds:, settle:, waitSeconds:) Spreads two fingers apart = zoom in. scale must be greater than 1. durationSeconds is capped at 10 seconds by default — pass maxGestureSeconds: to allow up to 60 for this one call.
pinchIn(sel?, scale: 0.5, durationSeconds: 0.5, maxGestureSeconds:, settle:, waitSeconds:) Pinches two fingers together = zoom out. scale must be greater than 0 and less than 1. Same cap as pinchOut.
gesture(sel?, maxGestureSeconds:settle:waitSeconds:) { FTFinger(x:y:).move(x:y:durationSeconds:).hold(seconds:) } Replays one or more finger paths as a single continuous touch — for a pattern-lock swipe, a long-press that then drags, a two-finger rotate, or anything pinchOut/pinchIn/doubleTap/swipeBy cannot express.
setPickerValue(sel, value, waitSeconds:) Sets one picker wheel — an iOS pickerWheel (date/time picker, UIPickerView) or an Android NumberPicker (shown as pickerWheel) — to a value in one step, so you do not drag a wheel or type into its field. Returns the element it grabbed. See the setPickerValue section below.
setSliderValue(sel, number, waitSeconds:) Sets a slider to a number in one call. The number is what the snapshot shows as the slider's value (a % sign is ignored)
hold(sel, holdSeconds: 3, maxGestureSeconds:, settle:, waitSeconds:, scroll:, maxSwipes:) { … } Runs the block while the finger stays down (for checking a component that only shows while pressed). holdSeconds defaults to 3 seconds. See the hold section below.

When the centre of the target is outside the screen, doubleTap, a long press (tap(sel, holdSeconds:)) and (on Android) pinchOut / pinchIn fail without sending anything, because a touch outside the screen lands nowhere. Targets larger than the screen are not refused. Scroll the target into view first.

See swipe for swipeBy(sel?, dxRatio:dyRatio:durationSeconds:), the panning gesture these are usually combined with.

Example

doubleTap("#photo")
pinchOut("#map", scale: 2.5)
pinchIn("#map", scale: 0.4)
swipeBy("#map", dxRatio: -0.3, dyRatio: 0.0)   // pan left

gesture: a multi-finger path that never lifts

gesture("#pad_map") {
    FTFinger(x: 0.3, y: 0.35).hold(seconds: 0.3)
        .move(x: 0.6, y: 0.35, durationSeconds: 0.3)
        .move(x: 0.6, y: 0.65, durationSeconds: 0.3)
}
gesture("#pad_map") {                 // two fingers = a hand-built pinch
    FTFinger(x: 0.45, y: 0.5).move(x: 0.2, y: 0.5, durationSeconds: 0.5)
    FTFinger(x: 0.55, y: 0.5).move(x: 0.8, y: 0.5, durationSeconds: 0.5)
}

Unlike calling swipePointToPoint (or any other gesture command) repeatedly — each call lifts the finger — every FTFinger in a gesture block is replayed as one continuous touch sequence: fingers touch down, move/hold in order, and only lift at the end of their own path. Coordinates are ratios of the target's frame (0...1 is inside it; a point outside is fine as long as it's still on screen), so the same gesture works at any resolution. Omitting the selector targets the whole screen; loops and branches are allowed inside the block. Limits: 1–5 fingers, up to 625 points per finger, total duration capped at 10 seconds by default (maxGestureSeconds: raises it to 60, same rule as the other gesture commands). To put a finger down late, use FTFinger(x:y:startSeconds:) (startSeconds is the delay in seconds from the start of the gesture until that finger touches down; default 0 — meant for fingers after the first. It must be a finite value of 0 or more). An invalid spec (no fingers, an off-screen point, a non-positive duration, too long a gesture) fails the step without touching the device.

On iOS this command always runs through XCUITest, even in the default inapp-boost mode. Use cases: pattern lock, long-press-then-drag without lifting (e.g. reordering a list), a custom two-finger rotate, gestures needing 3+ fingers, drawing or signing. On an older Xcode without this API it cannot be sent and the step fails (unlike pinch, there is no alternative path).

setPickerValue: set a picker wheel by value

setPickerValue("#hour_wheel", "19")     // the wheel the snapshot lists as pickerWheel
setPickerValue(".pickerWheel[2]", "30")  // the second wheel (minutes) of a time picker

setSliderValue: set a slider by value

setSliderValue("#slider_volume", 75)
select("#txt_slider").textIs("volume=75")

hold: verifying something that only shows while pressed

tap(sel, holdSeconds:) presses and releases within one step, so a component that only appears while a finger is down (a tooltip, for example) is already gone by the time anything runs after it. hold keeps the finger down for the whole block instead:

hold("#btn_tooltip_anchor", holdSeconds: 3) {
    select("#txt_tooltip").textIs("This is a tooltip")
}

The finger lifts by itself holdSeconds after it went down; the block runs while it is still down. If the block finishes before holdSeconds is up, hold waits for the release before returning. If the block takes longer than holdSeconds, the finger is already up for the rest of it — this is noted but not treated as a failure. Holds cannot be nested (start a second one only after the first one's block has finished), and if the target cannot be resolved the block does not run at all. On iOS in the default inapp-boost mode, the press always runs through the XCUITest bridge (same as tap's long press).

Maps, image viewers, drawing canvases

For a map, image viewer, or drawing surface, operate it with these four commands: swipeBy to pan (diagonal included), pinchOut/pinchIn to zoom, doubleTap to zoom in. Three things to keep in mind:

Notes