Writing tests
A test is a .txt file with one step per line, written the way you would say it to a person. The vision model finds what each step describes on the real screen.
Anatomy of a test
In the app repo, tests live in mt-tests/<case>/. Each case folder needs an INSTRUCTION.txt and at least one test .txt. Tests run in file-name order (01_…, 02_…).
START_RECORDING
WAIT: 2
VERIFY: The EULA screen is showing
CLICK: Agree
SNAPSHOT: home mask=status_bar,nav_bar
STOP_RECORDING
The steps
| Step | Args | What happens |
|---|---|---|
VERIFY | description | Asks the vision model: does this element/state exist on screen? |
CLICK | description | Finds the element and taps its centre. |
INPUT | description "text" | Clicks the field, clears it, types the text. Quote values with spaces. |
SWIPE | up | down | left | right | Swipe in that direction. |
WAIT | seconds | Sleep. |
UNINSTALL / INSTALL | package name / apk path | App lifecycle (the iOS clean-state lever). |
SCRIPT | shell command | Runs on the MonkeyTester host, not the Mac — a script calling adb fails. |
DIAGNOSE | shell command | Diagnostic; its result never fails the test. |
START_RECORDING / STOP_RECORDING | optional limit seconds | Record on the controller; the file lands in the run's outputs/ when it stops. |
SNAPSHOT | <name> [mask=…] [tolerance=%] | Screen vs baseline. See Snapshots and layout. |
ASSERT_LAYOUT | <tag> <check> … | Tagged element positions in pt/dp. See Snapshots and layout. |
PLUGIN | <plugin> <action> [key=value …] [device=…] [timeout=s] | Run a device plugin action; passes only when the job ends passed. See Device plugins. |
Write descriptions as specifically as you can. The model can be agreeable — it may call a plain red rectangle a "red button". "the red rectangle with rounded corners in the card footer" beats "the button".
INSTRUCTION.txt and case headers
MODE: once
CLEAR_DATA: first
REINSTALL_APP: true
| Header | Values | Meaning |
|---|---|---|
MODE | once | everytime | Setup runs once before all tests, or before every test. |
CLEAR_DATA | everytime (default) | first | Android: with first only the folder's first test starts from cleared data; later tests just relaunch, so state from an earlier test (an accepted EULA, a provisioned device) carries over. iOS has no clear-data. |
REINSTALL_APP | true | false (default) | In a multi-case run, each case after the first keeps the app the run installed; true starts that case from a reinstalled app — the clean-state lever on iOS and Android. |
In a multi-case run, a case after the first that sets neither header keeps the app data the previous case left (Android as on iOS) — e.g. device-setup starts on Home after onboarding. Set CLEAR_DATA there to clear again.
Variables
- A bare
KEY=VALUEline (no space before=) stores a value; every later${KEY}in step args and plugin blocks is replaced. - A
KEY=valueline inside the test file overrides everything. - Settings → Test Variables persists values in
Run/config.json(test_variables) and has a Project selector: per-project values live inproject_variables[owner/repo]and apply only to that project's runs. Settings values override the repo defaults inmt-tests/scripts/config.json;MT_TEST_VARS(JSON) overrides all. - A
${KEY}with no value anywhere stays literal and fails where used — validate that plugin rule paths start with/.
Platform-only steps
Prefix any step with IF IOS: or IF ANDROID:. On the other platform it records as SKIPPED and does not fail the test. Several steps can share one condition:
IF IOS:
SNAPSHOT: local_network_prompt mask=status_bar
CLICK: Allow button
WAIT: 2
END IF
END IF IOS/END IF ANDROID must match the opener; blocks don't nest, and a missing or mismatched END IF fails the test on every device. A plugin block's own END works inside.
PLUGIN steps in a test
PLUGIN: fisher factory-reset
PLUGIN: fisher set-temp celsius=24
PLUGIN: fisher expect
GET /status -> 200 {"heater":"off","ok":true}
END
VERIFY: The dashboard shows the heater off
PLUGIN: fisher expect
heater normal
END
VERIFY: The heater runs again
PLUGIN: fisher clear
- Args are split shell-style, so quote values:
pattern="WiFi connected".device=andtimeout=are step options; everything else is a param, typed from the action's schema (GET /actions: int, float, bool, json). - The indented block up to a line that is exactly
ENDis sent as the action'sscriptparam. Blank lines drop,#lines keep,${VAR}resolves. - If the job isn't done 15 s after its timeout the runner cancels it and the step fails. An unknown plugin or action fails with the list of known ones. The job's log prints into the console log.
Running a test by hand
cd mt-tests/scripts
CONTROLLER_URL=http://192.168.125.71:8090 python3 run_on_device.py \
--device ZA2235GDS8 ../mt-tests/onboarding/01_eula_to_home.txt
--list-devices shows what the controller serves. Device ids are adb serials (USB or IP:PORT) or iPhone UDIDs. --case <name> labels a run's results case / test; --record-snapshots saves baseline candidates instead of comparing.
From the browser, open Build & Test (/build.html) or start a run through the viewer's new-test page. Runs queue one after another in submission order — Android and iOS alike, because they may share device hardware — and wait in phase queued until the previous run finished.
Reading results
- The run page (
test.html) shows every step with its screenshot, the press marker replay, videos, and for snapshots the actual/baseline/diff images. - Run folders:
Run/run_<timestamp>/withoutputs/(screenshots, videos),results/(per-test JSON),console.log,summary.txt,run_metadata.json. Multi-device runs isolate artifacts underdevices/device_N/. - A run where a test failed on one device marks that device's rest Cancelled; other devices still run everything.
- A run stuck with no filesystem activity for
MT_STALE_RUN_SECS(default 3600 s) is stampedinterruptedand reported as Error — e.g. after a host shutdown or a viewer restart.