Test code structure

in Japanese(日本語)

A scenario is built from scenario → scene → condition/action/expectation (CAE). This page explains what each level means for execution and reporting.

The CAE chain

Within one scene, condition / action / expectation can be chained repeatedly by connecting the blocks with .:

scene(2, "Navigate to a detail screen and back") {
    action {
        tap("#nav_selector")
    }.expectation {
        select("#screen_title").textIs("Selector")
    }.action {
        tap("#btn_back")
    }.expectation {
        select("#screen_title").textIs("Home")
    }
}

condition sets up the state the scene needs (often launchApp()), action performs operations, and expectation asserts. A scene does not need all three, and — as above — you can alternate action/expectation as many times as the flow needs.

Scene numbers and titles become report headings. Reports are organized scene → condition/action/expectation → step, so pick numbers and titles that describe what the scene is proving, not just "step 2".

Failure semantics

A failing command aborts the whole scenario: every step after it is skipped, across all remaining scenes — not just the rest of the current scene. afterEach() is the one exception; it still runs.

Raw Swift code inside a block is not skipped by this mechanism (only DSL commands are). If you have plain Swift logic you don't want to run after an earlier failure, wrap it in procedure("description") { } (see Descriptors) so it participates in the same skip behavior.

Per-step time limit

Each command (each step) has a 120-second wall-clock cap. If it doesn't return in time, the step fails and the in-flight work is cancelled rather than left running in the background. The whole scenario is capped too (scenarioTimeout in the run profile, 600 seconds by default), so raise scenarioTimeout as well when you chain long waits (Run profile settings). To change it for a single scenario, give @Test a value in seconds. It wins over the profile value (shorter ones too); zero or negative is a compile error (when an expression evaluates to zero or less at run time, the scenario fails without being started).

@Test("Full sync", scenarioTimeout: 1800)
func S0010() { scenario { /* … */ } }

A scenario is also stopped when its output stops. If no step result or log line appears for longer than twice the per-step cap plus a few seconds (250 seconds by default), it is treated as stuck and fails. A slow scenario whose steps keep progressing is not stopped. Commands where you write how long to wait (waitSeconds of ifCanSelect / repeatWhileCanSelect, httpRequest, doUntilTrue) are not stopped while they wait within that length. If code whose length is unknown, such as Swift inside procedure("description") { }, stays silent for more than 250 seconds, emit output such as print() along the way.

Structuring and passing values

group("name") { } labels a run of steps in the report without changing execution or failure behavior. procedure("description") { } runs a synchronous body (() throws -> Void; await cannot be written; DSL commands can be called inside, and the steps inside are recorded with a [description] prefix and folded in the report .md) as a single recorded step — this is how irregular handling and test-data setup are written directly in code instead of a fixed DSL vocabulary. Details: Descriptors.

Unasserted scenarios are flagged

If an expectation { } block contains no assertion commands, a warning is added to the report and log (not a failure) — this catches scenarios that perform actions but never check anything. fleetest run --dry-run (or ft_dry_run) finds this without touching a device; see dry-run.

Branching by OS

Two mechanisms exist for OS-specific behavior, at different levels:

Use platform: when an entire test doesn't apply to one OS; use ios { }/android { } when only a few steps inside an otherwise-shared scenario differ.