irregularHandler
Declares an in-app message (promo card, announcement) that may or may not appear, and closes it automatically whenever it does.
Functions
| function | description |
|---|---|
irregularHandler(detect, dismiss:, maxDismissals: 10) |
Declares an interruption. Whenever detect resolves during any later step (operation or assertion), it is closed automatically — dismiss is tapped if given, otherwise detect itself is tapped. Typically declared once in beforeEach(). |
Example
func beforeEach() {
irregularHandler("#promo_modal", dismiss: "#btn_promo_close")
}
Notes
- Fires during both operation and assertion waits. Because assertions poll each cycle
against the current tree, a modal that opens while a scenario is waiting on
exist/textIsgets closed too, not just when the scenario is mid-tap. - Up to 10 closes per step by default (
maxDismissals:to change it; a value of 0 or less is treated as 1) — enough for a modal that reopens mid-step. If the same thing is still on screen after two closes, the tool gives up and records that it was not fully closed. - Conditions close interruptions before answering.
ifCanSelectandrepeatWhileCanSelectclose a declared interruption first, then judge — otherwise a covered target would silently read as "not found" and the scenario would take a wrong branch instead of failing loudly. Whether it was dismissed is recorded even when the condition itself does not resolve. - Does not touch OS system dialogs (permission prompts, "Open in …?"). Those are drawn by a
separate process and are outside what
irregularHandlercan see — see iosAlertHandler. - Modals in a separate window (iOS): some in-app message SDKs draw on a separate
UIWindowrather than the app's key window. The tool still sees these:- The modal itself is in the tree (
existfinds it,irregularHandlercan close it). - A screen it fully covers drops out of the tree —
existon something underneath fails and a tap on it fails as "not found", so a covered screen never reads as a false pass. - A modal covering only part of the screen (a top banner, say) leaves the rest of the tree in place — the judgment is whether the front window actually receives the touch at that spot, not whether the element is visually hidden.
- Taps, scrolls, and screenshots all reach the frontmost window at that point, not necessarily the app's main window.
- The modal itself is in the tree (
The interruption swallowed an interaction
If a declared interruption appears between sending an interaction and it taking effect, the tool cannot tell whether the interaction already landed. It never resends it — resending could double-fire something that already went through (a submit, a purchase). (The one exception is an interaction known not to have been delivered — a tap blocked by an iOS system alert; see iOS system alerts.) If the step that closed the interruption then fails, a note like this is recorded:
the interruption appeared during this step — an interaction sent just before it
may have been swallowed by it (nothing was re-sent: repeating it could double-fire)
Recovering from this is the scenario's job — check whether the intended state was reached (e.g.
ifCanSelect) and repeat the tap if not, but only for interactions that are safe to repeat.
A navigation tap is safe; a confirm/submit/pay action is not, since only the scenario's author
knows which is which.
Using it from MCP's ft_batch
The same declaration can be written as one line in ft_batch's steps (quoted, space-separated arguments,
like the other steps).
irregularHandler 'Stay safe on your route' dismiss: 'OK'; tap '#station_row'; tap '#route_card'
- It applies only to the later steps of that call. It is not carried over to the next call — write it in each call that needs it.
- The declaration does not touch the device (it closes the interruption only when one is showing before a later step sends its interaction — at the start, while it re-reads the screen to find its target, or while it waits for the target to become enabled).
ft_draft_scenariowrites it once as anirregularHandler(...)line, even if several calls declared it.ft_batchdoes not takemaxDismissals:(the default limit applies).