Skip to content
Rehearsev1.2.0

Write flows

A flow file lists the steps a person takes, by the names a screen reader says.

flows/basket.flow.yaml
name: The owner adds two things to the basket
service: web
steps:
- fill: Search
with: pens
- click: Add to basket
role: button
- click: Add to basket
- snapshot: Basket
role: status

Run it with --json to see what Rehearse observed.

Terminal
rehearse run flows/basket.flow.yaml --json

The observation’s observed part holds the tree after each step.

Terminal
{
"kind": "flow",
"driver": "browser",
"said": null,
"steps": [
{
"n": 1,
"step": { "open": "/" },
"ok": true,
"says": null,
"tree": "- main:\n - heading \"Shop\" [level=1]\n - paragraph: Signed in as the owner\n - link \"Sign in\":\n - /url: /login\n - text: Search\n - searchbox \"Search\"\n - status \"Basket\": 0 in the basket\n - button \"Add to basket\""
},
{ "n": 2, "step": { "fill": "Search", "with": "pens" }, "ok": true, "says": null, "tree": "…" },
{ "n": 3, "step": { "click": "Add to basket", "role": "button" }, "ok": true, "says": null, "tree": "…" },
{ "n": 4, "step": { "click": "Add to basket" }, "ok": true, "says": null, "tree": "…" },
{
"n": 5,
"step": { "snapshot": "Basket", "role": "status" },
"ok": true,
"says": null,
"tree": "- status \"Basket\": 2 in the basket"
}
],
"errors": []
}

A flow is a few steps a person takes, written by the names a screen reader says: click “Add to basket”, fill “Search”. Rehearse opens the page, takes each step, and observes the accessibility tree after each one. A flow names things the way people do, so it survives a change of markup and fails when a name changes.

  1. Point the manifest at your flows. List the flow files under scenarios.flows.

    rehearse.yaml
    scenarios:
    flows: ['flows/*.flow.yaml']
  2. Say where it starts. service: opens that service’s page (default scenarios.flows.service, then the default service). start: is the path to open, such as /settings (default /). Or piece: opens a piece’s canvas instead; see a flow over a piece.

  3. Say who and from where. person: signs in as that person (default the default person). world: starts from that world (default the default world).

  4. Write the steps, one to sixty:

    Step Does
    click: Add to basket Clicks the one element with that name
    fill: Search with with: pens Fills the field with that name
    type: pens Types into whatever has focus
    key: Enter Presses a key, named as Playwright names it: Enter, Escape, Tab, ArrowDown, Meta+k, ControlOrMeta+j
    snapshot: Basket Observes that one element’s tree

    role: narrows a click, fill or snapshot to one role (button, link, switch, status, any ARIA role). Use it when two things share a name.

  5. Run it by its path, which is its id.

    Terminal
    rehearse run flows/basket.flow.yaml

Step 1 of every result is opening the page. Each step after it keeps the tree once the page stops changing, and a screenshot (kept as a file, shown on the stage, never compared). A step that stops ends the flow; the result says which step, and why.

Rehearse’s browser also keeps the errors the page logged during the flow, in errors. A comparison compares them as it does a piece’s: a new error is a difference, never a failure.

A name must match exactly, capitals included, once spaces are tidied. When nothing has it, Rehearse lists what is close on screen.

Terminal
Nothing on screen is named “Add to baskets”. Close to it on screen:
button “Add to basket”
status “Basket”

When more than one thing has it, Rehearse lists them and asks for a role.

Terminal
More than one element is named “Sign in”: give `--role` to say which.
heading “Sign in”
button “Sign in”

An action that doesn’t finish in five seconds stops with “didn’t answer in time”.

A reach script is a flow too: a module whose default export is { name, steps }, as Ashlar writes them. Rehearse reads the default export as plain data (strings, numbers, booleans, arrays, objects; satisfies and as const are fine) and never runs the module.

flows/settings.reach.ts
export default {
name: 'Settings',
service: 'desk',
steps: [
{ click: 'Ask before closing', role: 'switch' },
{ snapshot: 'Ask before closing', role: 'switch' },
],
} as const;

List reach modules beside flow files in the manifest.

rehearse.yaml
scenarios:
flows: ['flows/*.flow.yaml', 'flows/*.reach.ts']

A module can say name, service, piece, start, world, person, covers and steps. A default export that computes its steps, or isn’t plain data, is refused with the reason.

Some screens only render as a story: the app around them needs a desktop shell or a server you can’t run. A flow can open a piece’s canvas instead of a service.

flows/counter.flow.yaml
name: Adding to the basket counts up
piece: src/Counter.stories.tsx#Default
steps:
- click: Add one
role: button
- click: Add one
- snapshot: Counter
role: region

A comparison names each step whose tree changed on the canvas.

Terminal
$ rehearse compare --base main
…
Adding to the basket counts up (flows/counter.flow.yaml)
step 1 (open piece src/Counter.stories.tsx#Default) line 3: "- status: 0 in the basket" → "- status: 0 in your basket"
step 2 (click “Add one” (button)) line 3: "- status: 1 in the basket" → "- status: 1 in your basket"
step 3 (click “Add one”) line 3: "- status: 2 in the basket" → "- status: 2 in your basket"
step 4 (look at “Counter” (region)) line 2: "- status: 2 in the basket" → "- status: 2 in your basket"

The piece renders as it does for piece scenarios, with the manifest’s preview, styles and config. The flow itself needs no service. This is how to try what a story’s play function would have done.

A flow signs in as its person through the person’s browser: entry. {{token}} is the person’s token from the sign-in.

rehearse.yaml
signIn: node people.mjs
people:
owner:
default: true
browser: { headers: { Authorization: 'Bearer {{token}}' } }
clerk:
browser:
steps:
- click: Sign in
role: link
- fill: Name
with: the clerk
- click: Sign in
role: button
Way What Rehearse does
headers Sends them with every request the browser makes
storage Puts each value in localStorage before the page’s own scripts run
cookies Sets each cookie (name, value, an optional path) on the service’s origin
steps Takes these steps on the service’s own page before the flow opens. They are never observed or kept.

Run as the clerk (rehearse run flows/basket.flow.yaml --as clerk), the flow’s tree after step 1 starts with these lines.

The tree after step 1
- main:
- heading "Shop" [level=1]
- paragraph: Signed in as the clerk

A person with no browser: entry can’t sign a browser in. The flow runs signed in as no one, and the result says so in said: owner has no browser sign-in in the manifest, so the flow ran signed in as no one. On a piece’s canvas, headers, storage and cookies apply; sign-in steps don’t, since a canvas has no sign-in page.

A step’s with: can use {{token}} too. The step kept in the result is the one you wrote, never the filled one.

Some products already have a driver: a command that runs the app and takes one step at a time, such as pnpm drive. Name it in the service’s drive:, and every flow on that service goes through it instead of Rehearse’s browser.

rehearse.yaml
services:
desk:
describe: The app in a browser, through pnpm drive
up: pnpm drive start --scenario {{world}}
ready: { command: pnpm drive snapshot --json }
down: pnpm drive stop
# Drive makes its own folder and refuses one it didn't make: point it inside this copy's scratch folder.
env: { DRIVE_DIR: '{{scratch}}/drive' }
drive: pnpm drive
timeout: 240

Read it top to bottom:

  • up starts the app on the world, so {{world}} goes there: the driver builds its own seeded worlds.
  • up and down are the driver’s own start and stop; ready asks the driver for a snapshot.
  • {{scratch}} is this copy’s own scratch folder. The base and the head each get one, so their drivers never share state. This driver refuses a folder it didn’t make, so the manifest points it at a new folder inside.

For each step, Rehearse runs the driver with the step’s words and --json, such as the following commands, and reads the last line each prints.

Terminal
pnpm drive click --name 'Ask before closing' --role switch --json
pnpm drive snapshot --json

After each action it takes a nameless snapshot, so every step has a tree, as with Rehearse’s browser. A driver answers in the drive result shape: {"ok": true, "command", "ms", "file", "tree"}, or {"ok": false, "command", "ms", "failure", "says"}.

The flow’s observed part then names the driver, and what it couldn’t do.

Terminal
{
"kind": "flow",
"driver": "service",
"said": "desk's driver signs in as no one, so the flow ran without owner.",
"steps": [
{
"n": 1,
"step": { "open": "/" },
"ok": true,
"says": null,
"tree": "- heading \"Settings\" [level=1]\n- switch \"Ask before closing\" [checked=false]\n- status: quiet"
},
{
"n": 2,
"step": { "click": "Ask before closing", "role": "switch" },
"ok": true,
"says": null,
"tree": "- heading \"Settings\" [level=1]\n- switch \"Ask before closing\" [checked=true]\n- status: quiet"
},
{
"n": 3,
"step": { "snapshot": "Ask before closing", "role": "switch" },
"ok": true,
"says": null,
"tree": "- heading \"Settings\" [level=1]\n- switch \"Ask before closing\" [checked=true]\n- status: quiet"
}
]
}

What a driver can’t do:

  • Sign in. A driver signs in as no one; the result says so in said.
  • Fill. A driver takes no fill step: click the field, then type.

Each flow starts where its world starts. Between two flows on the same driver, Rehearse runs the world’s before, brings the app down and up again with the service’s down and up, then runs the world’s add. So no flow starts where the last one left the app.

That needs a down command, and an up that hands the app over to a daemon and exits. When the service can’t be brought up afresh, the flows share the app, in order, and each later flow’s said says it started where the last one left the app.