Agent guide: from an app screen to a passing scenario
This page is for AI assistants (agents) that write fleetest scenarios through the ft_* MCP tools.
It is the short version of the runbook (.claude/skills/fleetest-scenario/SKILL.md in the clone);
read the runbook when you need the full rules.
The loop
- Pick the device.
ft_list_devices, then pass the sameprofile:(a run profile name) — orudid:/port:/serial:— to everyft_*call, so exploring and running use one device. - Explore.
ft_launchthe app, thenft_snapshot. Each row is[ref] Type "label" id=… (x,y WxH). Move withft_tap/ft_typebyselector(#idor a label — it survives redraws, alerts and scrolls that make refs stale, and the step becomes a scenario line as written); userefor x/y only for parts with no label or id. Once you can name several steps by selector,ft_batchruns them in one call. For long lists useft_scroll_towith a selector instead of repeatingft_swipe. Take a snapshot of every screen you pass — the dry-run checks#ids against them. - Draft.
ft_draft_scenarioturns the operations since the lastft_launchinto Swift and returns it as text (it writes no file). Cut detours withdrop:/lastN:. The expectation blocks come back empty on purpose — fill them from what the snapshots showed. The waits you paid while exploring (waitFor) are not carried over either — a draftedtap("#id")looks for its target for only about 0.7 s, so addwaitSeconds:or anexist(...)before steps on a screen that appears late. - Write the file under
TestProjects/<project>/scenarios/<name>.swift. - Compile.
ft_list_scenariosbuilds the project and returns compile errors as-is. - Dry-run.
ft_dry_runneeds no device. A selector syntax error fails it (isError).⚠️lines (an expectation with no assertion, an#idnever seen in a snapshot) are not failures, but fix them anyway. - Run.
ft_run_scenario. A failure is isError and carries the failing step, the element list and a screenshot at the moment of failure, and the report path. Read the element list first — the screenshot cannot give you an#id. On iOSft_run_scenarioalways runs on the XCUITest bridge and, by default, without FM/Vision (no text visibility check); confirm under production conditions withft_start_run.
A scenario
import FTDSL
@TestClass
class SignInExample {
@Test("Signing in shows the home screen")
func S0010() {
scenario {
scene(1, "The sign-in screen opens") {
condition {
launchApp()
}.action {
tap("#btn_signin")
}.expectation {
exist("#field_email")
}
}
scene(2, "Signing in lands on home") {
action {
type("#field_email", "user@example.com")
ifCanSelect("#btn_dismiss_tips", waitSeconds: 1) {
tap("#btn_dismiss_tips")
}
tap("#btn_submit", scroll: .down)
}.expectation {
select("#txt_title").textIs("Home")
}
}
}
}
}
scene= one screen.condition(preconditions) →action(operations) →expectation(checks). Anexpectationwithout an assertion checks nothing.ifCanSelecthandles a dialog that may or may not appear.scroll: .downreaches an element below the fold.- Do not guess command names.
ft_dsl_commandslists every command and its signature; a name that is not in that index does not exist.
Passwords, test data and APIs
- Do not write passwords or accounts into scenarios. Read them with
account("[user1].password")and put the values in the project'sdataset/accounts.json(test data that does not depend on the screen goes todata("[order1].item")anddataset/data.json; files such as a CSV or a JSON body go indataset/anddataFile("csv/users.csv")returns their location). If you do not know a value, ask the user — do not put a guessed value. - For users who do not want real passwords in git, have them put a file of the same shape in
~/.config/fleetest/dataset/<project>/on that Mac (it overrides per attribute). Agents do not write to~/.config/fleetest/. - Masking
account()values as***in reports is a setting of that Mac (redactAccountValues); by default they are not masked. - To prepare test data through an API, use
httpRequest(url, method:, headers:, body:)and check the response'sstatus/text/jsonwiththisIs. localhost is reachable as is; external hosts only when they are in that Mac'ssandbox.allowedDomains(Network access from scenarios). - Do not declare a
varat file level (Swift 6 rejects it at compile time). Each@Testruns in its own process, so values do not carry over; to pass a value between tests, usewriteRunMemo/readRunMemo(writeMemo/readMemolive only within one test function).
Selectors
- Prefer
#id. A bare label ("Home") matches the whole label exactly;*text*is a wildcard for dynamic text only. .type[n]breaks when siblings are added or removed. Scope it instead:#container >> .button. The ancestor must have its contents under it in the tree, though: on iOS, a Compose Multiplatform Row/Column with only atestTaghas nothing under it, so the scope matches only on Android. For a scenario that runs on both OSes, check that it passes on iOS too; if not, write a unique#idor a relative selector.- Never write a selector you have not seen in a snapshot.
Make it independent of the screen size
- Reach anything below the fold with
scroll:orscrollTo— do not assume it is visible. - Start and end a swipe on elements that are surely inside the window.
- Do not assume how far one swipe travels, and do not use
notExistto prove that something scrolled away (how many rows stay in the tree depends on the window height).
When a run fails
| What the failure says | What to do |
|---|---|
| element not found | Look for the element in the element list at failure. A changed #id shows up there with its new value; an element that exists but is off screen needs scroll: |
| another window was in front of the app | A system alert or overlay swallowed the input. Handle it (ifCanSelect, or an alert handler — see the command reference) |
| the app process was not running | The app crashed. Check ft_logs before touching the scenario |
| an assertion failed with the actual value | Compare with the element list; fix the expected value only if the app is right |
Runs the user asks for
ft_run_scenario is for checking while you write a scenario; it leaves no result history (results/) and no recording.
When the user asks you to run tests, use ft_start_run. It starts the same run as fleetest run --profile in the
background and returns at once; follow progress and the result with ft_run_status (stop it with ft_stop_run).
ft_start_run may ask the user for approval, depending on their settings. If it is refused, do not work around it
with fleetest run in the shell or similar; tell the user the run needs their approval (the approval setting is the
safety line the user chose).
It runs inside the MCP server, so it also works for agents whose shell is sandboxed.
To have the services the app depends on (compose.yaml) up for exploring or Live Control, use ft_services (action: up). ft_start_run takes them over and restarts them, so there is no need to down them afterwards.
| Request | Tool (arguments) |
|---|---|
| Run (all, a class, one test) | ft_start_run (profile, and scenario: ["<Class>[.<method>]"] if needed) |
| Only what failed last time | ft_start_run (profile, failed: true) |
| Once on every device | ft_start_run (profile, broadcast: true) |
| Result, failed scenarios and their reports | ft_run_status |
| Unstable, slower or regressed tests | ft_results (query: "flaky" / "slow" / "insights") |
| The execution log of a run | ft_results (query: "log", runId default latest, optionally scenario) |
ft_results prints the same text as fleetest results <query>. Do not add app: to a scenario or point at a bridge port by hand
to run it on every device.
Pausing or retiring tests
Do not move files into _disabled/; mark them. Both marks drop the test from bulk runs; it runs only when named by its exact ID.
- Unfinished:
@Draft("reason") - Retired:
@Deleted("reason")
Both can be put on a class or on an individual @Test.
Naming devices in reports
In reports to the user, do not call a Simulator or Emulator a "physical device". That word means
only a real iPhone / Android handset (connected over USB or Wi-Fi; kind: "physical" in the run profile). When unsure, say "device".
Before putting an attribute on a class
Before @RunOnSingleMachine / @RunOnSingleDevice / @RunInOrder (+ @Order), first ask whether the tests can be made independent
(prepare test data in the test's own range, with an account of its own and unique names; see Where to put test data).
A flow that needs an order goes into a single @Test first. Add an attribute only when it is needed
(Running a class in one place or in order).
Known caveats
Before writing a scenario, always read Known caveats. It lists the caveats of commands and UI components (including operations that go wrong silently), one line each. If a line applies to a command you use or a component on the screen, read the linked section and write it the way it says.
Writing for specific UI components
If the screen has stock Material3 components (pager, bottom sheet, dropdown menu, date picker,
drawer, pull-to-refresh, snackbar, search bar, autocomplete, …), read the matching section of
UI component patterns and quirks before writing. It covers
component-specific patterns — the screen behind a modal drops out of the tree, a field's content is
in .value, horizontal containers need scrollFrame: — and workarounds for the tool's current
limitations.
Links
- MCP server
- AI assistants other than Claude Code
- Command reference (the per-command pages under "Functions and properties")