iOS system alerts (iosAlertHandler)
Announces one upcoming iOS system alert (permission prompt, ATT, "Open in …?") and the button to press on it.
Functions
| function | description |
|---|---|
iosAlertHandler(alert:, button:) |
Registers one upcoming system alert. alert: (which alert, matched against its title) is required. Both alert: and button: use selector matching syntax (|| for alternatives, * for the match mode). Registers are consumed on press: register again for a second alert. |
Example
iosAlertHandler(alert: "*Photo Library*", button: "Don't Allow")
iosAlertHandler(alert: "*wants to track*||*トラッキング*",
button: "Allow||許可") // both locales
Notes
- You may register the same title several times with different buttons; the one that matches a button on the alert actually shown is pressed (for example an OS update nag that appears as two alerts, with "Later" and "Remind Me Tomorrow").
- An empty alternative, or one with nothing but
*and invisible characters (for example"\u{200B}*"), fails at the declaration — it would match any alert.
Why this exists
Permission prompts, "Open in …?", and similar system alerts are drawn by SpringBoard, a
separate process — they never appear in the app's own accessibility tree, so
irregularHandler cannot see or close them.
| mode | how to handle alerts |
|---|---|
| inapp-boost (run profile default) | Write them normally — tap("Allow"), exist(...), ifCanSelect(...) all reach across to SpringBoard when the app itself cannot resolve the selector. Nothing closes automatically unless you register it with iosAlertHandler. |
| xcuitest | Write them as with inapp-boost. |
The only alert closed automatically without any declaration is openURL's first-time
confirmation.
Registering
-
alert:is required. The button label alone does not say which window it belongs to — without a title match, the tool could press a button on an unrelated alert (a different app's permission request queued to the front). -
Both fields use the same matching syntax as selectors: bare = exact match,
x*= prefix,*x= suffix,*x*= contains. Alert titles embed the app's display name (""MyApp" Would Like to Access…"), soalert:is written*x*in practice.#id/.typecannot be used (they are matched as literal text, so they never match a title or button and nothing is pressed). -
One call announces one alert. The registration is consumed once a matching alert is pressed; register again to handle a second alert. Register before the action that triggers the alert —
beforeEach()works, registering it once per@Test(same lifetime asirregularHandler). -
Registrations are tried in order, and only pressed when the scenario's own requested element could not be resolved on either the app side or SpringBoard side — an alert the scenario is operating directly (
tap("Allow"),ifCanSelect) is never taken from it. -
A registration is also consulted when
ifCanSelectdoes not resolve — so a chain like the one below still gets past an alert sitting on top of it, instead of the whole chain reading "not met" and the alert being pressed too late:ifCanSelect("#btn_start||Get Started") { tap("#btn_start||Get Started") } ifCanSelect("#btn_agree||I Agree") { tap("#btn_agree||I Agree") } -
Labels match exactly, and the tool never guesses a default button. Which button is the "yes" answer is context-dependent (permission prompts have variants like "Allow Once" / "Allow While Using App" / "Don't Allow") and both wording and order vary by locale and OS version. Only the labels you write are pressed — no partial matching unless you add
*, sobutton: "Allow"never presses "Don't Allow" by accident. Register the reject-side label the same way to auto-decline instead. -
Pressing an alert is recorded in the execution log, including which button was pressed — permissions have lasting effect, so a silent auto-press would be a trap later. This also covers presses on alerts unrelated to the app under test (another app's queued permission request that surfaced in front).
While a system alert covers the app
This only applies while an iosAlertHandler registration is still pending. When an alert is
covering the app, operations and assertions against the app do not proceed — the tool waits for
the alert to clear (or be closed by a registered button), and fails with
failureKind=system-ui-covered if it never does:
❌ 6. [action] tap "#btn_something"
system UI is covering the app ("MyApp" Would Like to Access the Photo Library).
The in-app bridge could still reach the app, but a person could not, so the step was not
performed. None of the registered iosAlertHandler entries
(*Photo Library*→Allow) matched a button on it.
Buttons on this alert: "Select Photos" / "Allow Full Access" / "Don't Allow".
Register the one you want pressed with iosAlertHandler(...), or dismiss it in the scenario.
- The failure message lists the alert's actual buttons — since labels match exactly, this is the way to learn the correct string without capturing a fast-vanishing alert on video.
- A failure that happens under a system alert leaves the app's element list out of the report (nothing in it could be reached) and says so; the alert's title and buttons are in the failure message instead.
- This exists because the in-app bridge's tap is a direct call, not an OS touch event — it would otherwise reach the app underneath a covering alert, something a real person could not do. Android is not affected (its element tree is rooted at the active window, so covered app elements simply drop out of the tree).
- Elements the app itself is presenting (a modal it drew) are unaffected — only OS-drawn UI covering the app triggers this.
- A passing assertion is checked the same way: if it turned green while covered, the tool tries to clear the cover and re-checks on the clear screen before accepting it.
Consequences of leaving an alert on screen
- A scenario that triggers an alert must close it within that same scenario. SpringBoard
draws it, so it survives
terminateApp()and evenremoveApp()— it stays on screen for whatever runs on that device next. - fleetest dismisses a leftover alert before the next scenario starts, in this order:
- If it has a button that decides nothing —
Cancel/Close, orOKwhen it is the only button (and the same labels in a Japanese UI) — fleetest presses it (under a second; works on physical devices too). - If it is a permission dialog, fleetest presses its deny button (
Don't Allow, and its Japanese counterpart). The app's permission for it is now denied, and the scenario's log says so; a scenario that starts withclearAppData()is back to undecided anyway. - If it is the iOS software update alert (titled
Software Update), fleetest pressesLaterto defer it (no update is installed during a test). If the follow-up choice ofInstall Tonight/Remind Me Laterappears, it pressesRemind Me Later. The installing buttons (Install Now,Install Tonight) are never pressed. This works on physical devices too. Only an alert left on screen before a scenario starts is deferred this way; an update alert that appears in the middle of a scenario is an interruption like any other, for the scenario to close (iosAlertHandler). - Otherwise, on a Simulator, fleetest restarts SpringBoard without pressing anything and reconnects
to that device (about 20 seconds; needs a run profile,
--profile). An affirming button (Allowand so on) is never pressed. Labels are matched exactly. What was done appears in the scenario's log as🧹 … a system alert was left on screen before this scenario (…). On a physical device, or in a run without a run profile, an alert with none of the buttons above stays, a warning is printed before each scenario, and every following scenario on that device hits the covering failure above.
- If it has a button that decides nothing —
- A leftover alert survives across runs, too. A warning is printed at the start of a run if a device already has one on screen.
- An operation that goes through XCUITest is not delivered while an alert is in front.
This covers xcuitest mode, and in inapp-boost mode the operations the in-app bridge cannot perform
(home, the app switcher, coordinate drags and long presses). The step fails with
a system alert is in front of the app (title: …, buttons: …)and the alert is left as it is — without a registration, the tool never presses an alert button on its own and never retries the operation. With a registration, a tap is sent again: when an alert that was not there at the start of the step comes up just before the tap, that tap is known not to have been delivered, so the tool closes the alert with the registered button and sends the tap once more (the report notessystem-alert-retried). Typing, double taps and drags are not sent again — part of them may already have gone through. clearAppData()resets permissions, so the same prompts appear again on the next run — useful when a scenario should always start from the not-yet-decided state.- For using this from MCP, see MCP server.