Anh Tran dev notes

Production bugs from mobile and backend work, written up with the fix and how it was checked.

Note 09 / Testing / Android / Maestro

Maestro on a real Android phone: fast flows, rapid-tap tests and counting crashes instead of trusting green

Why Maestro idles for seconds before and after taps, which two waits to remove, how to write a flow that taps ten to thirty times without settling, and why the crash buffer, not the flow colour, is the verdict. Includes the sed trap that made a mutation test pass for nothing.

By
Trần Thế Anh, Software Engineer
Published
Work done
October 2026, Android test device (React Native and Flutter apps)
Stack
Maestro 2.10 (patched build), adb, bash, Python
Reading
5 min, 1,074 words

A Maestro flow on a real phone can take two minutes to do what a person does in twenty seconds. A flow can also finish green while the app crashed on step four. Both problems come from trusting the tool’s defaults. This note covers the changes that made flows run at human speed, the test that matches how users really tap, and how to decide whether a run passed.

Why flows crawl

Two hidden waits show up when you time each command. They were measured on a Redmi phone.

Conditions that fail still cost about seven seconds. A runFlow with when: or an optional command that is skipped or warned still waited. In the Maestro source, the orchestrator adjusts its wait to the latest interaction: for every condition that is not met, it waits max(0, 7000 - milliseconds since the last tap). The YAML when: has no timeout field to shorten it. The fix was a patched copy of the CLI, built from source, with that constant changed from 7000 to 1500. A script makes the copy and stops if the constant no longer appears exactly once, so a Maestro upgrade cannot be patched blindly.

“Wait for the screen to settle” never ends. A tap normally waits until the screen stops changing. A screen with a 3D avatar or a WebView never stops, so taps took about 3 seconds, swipes 12 to 14 and back around 11. The cure is explicit on every tapOn, swipe and inputText:

- tapOn:
    id: "send_button"
    waitToSettleTimeoutMs: 800

A value of 500 to 800 works for most screens. back has no such parameter, so use it sparingly.

Measure before guessing. A small script reads the commands.json that each run writes and prints every command that took four seconds or more, with its status. With the two fixes, one outfit flow went from 77 seconds to 57. A character-creation flow took 226 seconds, mostly because of nine swipes, which was a flow problem, not a Maestro one.

Wait on conditions, never on fixed sleeps. extendedWaitUntil with a string that will appear and the shortest timeout that is enough beats a long waitForAnimationToEnd.

The rapid-tap flow

Real users tap quickly, and sometimes many times in one second on the same button. A flow that taps once and waits 800 ms never finds a double-submit. So each suite has at least one flow like this:

- repeat:
    times: 20
    commands:
      - tapOn:
          id: "upload_button"
          waitToSettleTimeoutMs: 0
- assertNotVisible: "Upload failed"

Then check three things: the screen opened once and not twice, only one request or one ad went out, and nothing crashed or hit an ANR. A red rapid-tap flow is a bug in the app (a missing single-flight guard, no protection against double presses), not in the flow.

One caveat. If the app has a guard that swallows touches right after a box opens, the first deliberate tap in that box should wait about 400 ms. That is a justified exception to the no-fixed-waits rule. Do not add the wait before the burst itself.

Counting crashes

Flow colour is not evidence. A flow can pass while the app dies and restarts underneath it, and a flow can fail because a selector was wrong while the app is fine. The verdict comes from the device:

  • the crash buffer of logcat (adb logcat -b crash),
  • lines containing ANR in,
  • the process dying, as seen in the activity manager’s log.

A red flow with crash = 0 and ANR = 0 is almost always a flow problem: a selector, a timing, a regex. A suite runner prints a total of crash plus ANR plus JS fatals at the end, and that line is the number to report.

Traps measured along the way

  • hideKeyboard on Android is the Back key. It sends input keyevent 4 unconditionally. “hideKeyboard, then back” is two backs and can hide a double-open bug. pressKey: Escape does not dismiss the keyboard of some apps. To count screens opened, count activity starts in logcat instead of counting backs.
  • Two runFlow blocks in a row, when: visible X then when: notVisible X. If the first block makes X vanish, the second always runs. Put the notVisible block first or use a flag set with evalScript.
  • A BSD sed pattern that deletes nothing and exits 0. Mutation testing here means deleting a line of the code under test and checking that a test goes red. On macOS, sed '/a\|b/d' does not understand \|. It removes nothing and exits 0, so the test stays green and looks like it proves something. Use sed -E '/(a|b)/d' and run grep -c afterwards to confirm the count is 0 before running the test.
  • Install through a script that verifies. One whole run was judged on a stale build because the install output was cut with tail -1 and the run continued. The script now stops unless adb prints Success and the package’s lastUpdateTime is newer than the APK, and it records the install so each run compares it again.
  • Vendor ROMs can block the driver. On one Tecno phone the system’s boot manager refused to let the Maestro driver open another app (the log says the caller was the Maestro package, reason screen_on). Every launchApp failed and every flow was red with a launcher screenshot and zero crashes. adb shell am start still worked. The fix was to use another phone, not to change the phone’s settings.
  • --no-reinstall-driver on every command, maestro hierarchy included. Without it Maestro uninstalls its driver to reinstall it, the Xiaomi system refuses the install prompt, and the driver is gone.
  • Do not tap ad bodies, and test with real ad unit ids once the app has them, one pass only. Looping thirty rapid taps belongs on test ads.

What this does not prove

A fast, green, crash-free run on one phone shows the flow works on that phone and build. It does not show fill rate or load speed on other devices. Speed claims need a release build on a free device, not only passing logic tests.

I wrote this from the project’s testing notes and flow tooling, which I read. I did not run Maestro for this article, so the timings (77 to 57 seconds, 226 seconds with nine swipes, about 7 seconds per skipped condition) are the recorded measurements, not new ones.