Timeouts, waiting and retries
A test fails for two different reasons: the thing is not there yet (slow screen, slow backend) or it is never going to be there. FlutterProbe gives you a few layers, from the loosest to the most explicit. Each layer is off or sane by default and none of them changes a suite unless you ask.
1. The step timeout (always on)
Section titled “1. The step timeout (always on)”Every step has a time limit: defaults.timeout in probe.yaml or --timeout 45s (default 30s). A step that is not done by then
fails with what it was waiting for, a screenshot, and (for backend steps) the last requests the app made. restart the app and
clear app data use agent.launch_timeout instead (default 120s).
wait until "X" appears, wait for response ... and the other wait steps poll until their target shows up or this limit is hit.
2. Implicit wait (opt in, whole run)
Section titled “2. Implicit wait (opt in, whole run)”Without it, tap "Save" fails at once when the button is not on screen yet. With
probe test tests/ --implicit-wait 7s # or defaults.implicit_wait: 7stap, type, long press, double tap, clear, drag, a plain see, and the response checks (see response, store response,
if response) retry for up to that long before failing, like Maestro. It is meant for navigations and loads that finish a moment
later. don't see, steps with optional or if visible, and the wait steps are never retried this way.
3. A budget for one step: within
Section titled “3. A budget for one step: within”tap "Export" within 5 secondswait until "Report ready" appears within 90 secondswait for response "/api/export" status 200 within 120 secondssee "Done" within 500 mswithin N seconds|ms replaces both the step timeout and the implicit-wait window for that one step. Use it for the one slow
operation (an export, a payment, a cold backend) without raising the timeout of the whole suite, or to make a step fail fast.
4. Failing gracefully
Section titled “4. Failing gracefully”When missing is acceptable, say so instead of catching the failure later:
tap "Skip tour" optional # try it; a failure is logged, the test goes ontap "Allow" if visible # only when it is on screen right nowif "What's new" appears tap "Close"if response "/api/me" json "data.plan" equals "pro" see "Premium"otherwise see "Upgrade"if "X" appears checks once (about a second) and takes the otherwise branch when absent; if response looks at the newest
recorded response and is false when there is none.
5. Retrying a block or a whole test
Section titled “5. Retrying a block or a whole test”retry 3 times tap "Refresh" wait for response GET "/api/orders" status 200 within 5 seconds see "Order #1"retry N times runs the block again from the top when a step in it fails (only the last attempt’s error is reported). It is the
right tool for an action whose result is checked afterwards. For flaky tests as a whole, defaults.retry_failed_tests: 2 (or probe test --retry-failed 2) runs a
failing test again up to that many extra times before reporting it failed. A test that passes on a retry counts as passed and is
marked (passed on attempt 2 in the terminal, "attempts": 2 in the JSON report), so flakiness stays visible. Off by default.
A limit for each test
Section titled “A limit for each test”A step timeout bounds one step; a test of many steps can still run for a long time. defaults.test_timeout: 90s (or probe test --test-timeout 90s, which wins over the file) is a wall-clock limit for one attempt of a test. The file’s value is used when the flag is not given, and no value means no limit. A value below one second, or a negative one, stops the run before it starts.
When an attempt runs past the limit it fails with test exceeded 90s, naming the step it was on, and the run goes on. The cleanup then runs in this order: the failure screenshot, the on-failure hooks, the after-each hooks, the video stop, and the perf close. It has a 30 second total budget, and a cleanup call that does not return in time is given up. Then the app is restarted, so the next test starts clean, also after a cleanup that was given up. The restart has its own bound, agent.launch_timeout, and it is skipped only when the run itself was cancelled (Ctrl-C). The JSON report marks the test with timed_out and time_limit_seconds; without the limit those fields are absent. The JUnit report gives such a test a <failure type="test_timeout" message="test exceeded 90s">, and the HTML report marks its row with the limit.
A wait N seconds at or above the limit cannot end in anything but the limit, so it fails as soon as it starts, with a message that names the wait and the limit. Use wait until for the screen the test needs, or raise test_timeout. probe lint warns about such a wait where it is refused: in a test body, in a before-each hook, and in a recipe one of those calls. A wait in an after-each or on-failure hook is not refused, so it is not warned. A recipe that no test body or before-each hook of its own file reaches is warned with its condition, since a test in another file may call it under the limit.
The limit cuts a call only when the call honours its context, as step timeouts already require. A before each hook or a step in the body that ignores its context blocks the attempt, as it does with no limit. A recording stop is given the same budget: the scrcpy stop kills its process when the budget ends, while the screenrecord and simctl stops wait for their recording process, so an abandoned one of those lasts until that process exits.
A timed-out attempt is retried like any other failure. Each retry gets a fresh budget, so the worst case for one test is retry_failed_tests + 1 attempts of up to test_timeout each, plus each attempt’s cleanup: with retry_failed_tests: 2 and test_timeout: 90s, one test can take about 270 seconds of attempts before the failure is reported.
Each retry (retry_failed_tests) and each data-driven row gets its own budget. A composite test has one budget for all its device blocks. In a composite test the device blocks stop together at the limit, but their cleanup (the screenshot, the hooks and the restart) is not run yet.
Choosing
Section titled “Choosing”| The thing is… | Use |
|---|---|
| usually there, sometimes late | --implicit-wait 7s for the run |
| there only after one slow operation | within 90 seconds on the step that waits |
| optional (a banner, a tour) | optional, if visible, if "X" appears |
| the result of a flaky action | retry 3 times around action + check |
| a flaky test you cannot fix yet | --retry-failed 2 / defaults.retry_failed_tests (and fix it) |
| a backend answer | wait for response ... within N seconds, or mock it to make it deterministic (guide) |
Fail fast on purpose: a short --timeout with within on the few slow steps finds a missing element in seconds instead of
half a minute, and --fail-on-warning turns a tap that did nothing into a failure.