wait, waitForDisplay, waitForClose, waitForSettle

in Japanese(日本語)

Fixed pauses, explicit waits for an element to appear or disappear, and an explicit wait for the screen to stop moving.

Functions

function description
wait(seconds) Fixed sleep. Decimal seconds allowed.
waitForDisplay(sel, waitSeconds: 15) Waits until the element is displayed (does not scroll). Returns an FTElement, chainable the same way exist is. Fails the scenario if it never appears.
waitForClose(sel, waitSeconds: 15) Waits until the element disappears (does not scroll). sel is required — there is no "reuse the previous selector" shorthand.
waitForSettle(sel?, quietSeconds:, throwsException: true, waitSeconds: 15) Waits until the pixels of the screen (or of the element's frame, when sel is given) have not changed at all for quietSeconds, then until the accessibility tree has caught up, and returns true. Returns a Bool (@discardableResult, so it can be used in if). Details below.

Example

tap("#submit")
waitForDisplay("#confirmation_toast", waitSeconds: 10)
waitForClose("#loading_spinner", waitSeconds: 15)
wait(0.5)     // only for settling that no selector can express (e.g. an in-flight animation)

flickCenterToBottom()
waitForSettle()                    // let the scroll inertia stop completely
findImage("[Camera Icon]").tap()   // now the image is read from a still screen

Notes

waitForSettle

@discardableResult
waitForSettle(_ selector: String? = nil, quietSeconds: Double? = nil,
              throwsException: Bool = true, waitSeconds: Double? = nil) -> Bool

Waits until the screen has stopped moving. It waits only when you write it — ordinary operations (tap, swipe, scroll*, …) do not wait for the pixels to be still. Write it right before a step that reads the picture:

It matters most right after a scroll or a flick, when inertia may still be moving the content.

What it waits for

Two stages, both inside the limit waitSeconds:

  1. Image — the pixels of the compared region have not changed at all for quietSeconds.
  2. Tree — once the picture is still, the accessibility tree has caught up: two consecutive snapshots of the elements in the region are identical. (The tree can lag behind the picture, so the next step could otherwise resolve against an old tree.)

It returns true when both stages finish in time.

Arguments

argument meaning
selector Omitted = the whole screen. With a selector, the element's frame is the compared region. Use it to leave out things that never stop (spinners, shimmering skeleton placeholders) by passing an element that does not contain them. If the element cannot be found, the step always fails (see throwsException).
quietSeconds How long the screen must stay unchanged to count as still — the criterion. Range 0.1–5 seconds. The default depends on the app's UI framework: 0.8 s on iOS Compose Multiplatform (and when the framework cannot be determined), 0.5 s on other iOS frameworks and on Android. These are the longest gap between redraws measured at the end of scroll inertia (a 650 ms 1-pixel crawl on Compose Multiplatform, 368 ms on SwiftUI, 385 ms on Android under load) with about 20% margin.
waitSeconds The upper limit for the whole wait (finding the selector element + image + tree). If the element cannot be found, the step keeps looking until this limit and then fails. Default 15 seconds, like waitForDisplay / waitForClose / appIs. Range 0–60 seconds.
throwsException Default true. When the screen (or the tree) does not settle within waitSeconds: true = the step fails and the scenario aborts; false = the step passes with the note settle-not-reached and the function returns false.

Notes