Write flows
A flow file lists the steps a person takes, by the names a screen reader says.
name: The owner adds two things to the basketservice: websteps: - fill: Search with: pens - click: Add to basket role: button - click: Add to basket - snapshot: Basket role: statusRun it with --json to see what Rehearse observed.
rehearse run flows/basket.flow.yaml --jsonThe observation’s observed part holds the tree after each step.
{ "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.
Write a flow
Section titled “Write a flow”-
Point the manifest at your flows. List the flow files under
scenarios.flows.rehearse.yaml scenarios:flows: ['flows/*.flow.yaml'] -
Say where it starts.
service:opens that service’s page (defaultscenarios.flows.service, then the default service).start:is the path to open, such as/settings(default/). Orpiece:opens a piece’s canvas instead; see a flow over a piece. -
Say who and from where.
person:signs in as that person (default the default person).world:starts from that world (default the default world). -
Write the steps, one to sixty:
Step Does click: Add to basketClicks the one element with that name fill: Searchwithwith: pensFills the field with that name type: pensTypes into whatever has focus key: EnterPresses a key, named as Playwright names it: Enter,Escape,Tab,ArrowDown,Meta+k,ControlOrMeta+jsnapshot: BasketObserves that one element’s tree role:narrows aclick,fillorsnapshotto one role (button,link,switch,status, any ARIA role). Use it when two things share a name. -
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.
Match names exactly
Section titled “Match names exactly”A name must match exactly, capitals included, once spaces are tidied. When nothing has it, Rehearse lists what is close on screen.
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.
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”.
Reuse reach modules
Section titled “Reuse reach modules”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.
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.
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.
Run a flow over a piece
Section titled “Run a flow over a piece”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.
name: Adding to the basket counts uppiece: src/Counter.stories.tsx#Defaultsteps: - click: Add one role: button - click: Add one - snapshot: Counter role: regionA comparison names each step whose tree changed on the canvas.
$ 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.
Sign in
Section titled “Sign in”A flow signs in as its person through the person’s browser: entry. {{token}} is the person’s token from the
sign-in.
signIn: node people.mjspeople: 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.
- main: - heading "Shop" [level=1] - paragraph: Signed in as the clerkA 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.
Drive through a service’s own driver
Section titled “Drive through a service’s own driver”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.
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: 240Read it top to bottom:
upstarts the app on the world, so{{world}}goes there: the driver builds its own seeded worlds.upanddownare the driver’s own start and stop;readyasks 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.
pnpm drive click --name 'Ask before closing' --role switch --jsonpnpm drive snapshot --jsonAfter 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.
{ "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
fillstep: click the field, thentype.
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.
Read next
Section titled “Read next”- Comparing base and head: how step trees are compared.
- For agents: the same steps, one at a time, with
rehearse drive. - Scenario files reference: every field of a flow.