# Cases and steps

> How a job, its cases and their steps are written, and what each step does.

Source: https://docs.screwbugs.dev/screw-bugs/cases-and-steps

A **job** is one run: a URL and a list of **cases**, each a list of **steps** run in order. Whoever writes the cases (your agent, or you) decides what runs; screw-bugs decides each status.

## The model

- **Job**: `url`, `cases`, and optional `title`, `instructions`, `summary`, `device` (`desktop` or `mobile`) and `account`. `title`, `instructions` and `summary` are shown, never interpreted.
- **Case**: `id`, `title`, `steps`, an optional `success` sentence and an optional `continue`.
- **Session**: cases run one after another in one browser, recorded as one video. Cookies and storage carry over.
- **Start page**: a case starts at the job URL (or its first `goto`), unless it continues.

## An example

A `--spec` file for `screw-bugs run`. The MCP tool `start_run` takes the same job without `version`, and there `summary` is required.

```json
{
  "version": 1,
  "url": "http://localhost:3000",
  "title": "Sign-in after the refactor",
  "summary": "Signing in with a test account still reaches the dashboard and greets the user.",
  "cases": [
    {
      "id": "login-works",
      "title": "Signing in reaches the dashboard",
      "success": "The user lands on the dashboard and sees a welcome message.",
      "steps": [
        { "action": "goto", "url": "/login" },
        { "action": "fill", "target": { "label": "Email" }, "value": "test@example.com" },
        { "action": "click", "target": { "role": "button", "name": "Sign in" } },
        { "action": "expectUrl", "includes": "/dashboard" },
        { "action": "expectText", "text": "Welcome" },
        { "action": "screenshot", "name": "dashboard" }
      ]
    }
  ]
}
```

`screw-bugs schema job` prints the full JSON Schema.

## Step kinds

| Step           | Fields                                | What it does                                                   |
| -------------- | ------------------------------------- | -------------------------------------------------------------- |
| `goto`         | `url`                                 | Open a URL; paths resolve against the job URL. HTTP 400+ fails |
| `reload`       |                                       | Reload the page; judged like `goto`                            |
| `click`        | `target`                              | Click an element                                               |
| `hover`        | `target`                              | Move the pointer over an element                               |
| `fill`         | `target`, `value`                     | Replace the value of an input                                  |
| `upload`       | `target`, `files`                     | Choose files for a file input                                  |
| `press`        | `key`                                 | Press a key, such as `Enter`                                   |
| `expectText`   | `text`, `frame`?                      | Expect the text to become visible                              |
| `expectNoText` | `text`, `frame`? or `target`?         | Expect the text not to show, as text, alt text or label        |
| `expectUrl`    | `includes`                            | Expect the page URL to contain this                            |
| `expectLink`   | `target`, `href`, `match`?            | Expect a link to go to an address, without following it        |
| `waitFor`      | `target`, `state`?                    | Wait until the target is visible, hidden, attached or detached |
| `scroll`       | one of `target`, `to`, `by`; `frame`? | Scroll, then screenshot the view                               |
| `screenshot`   | `name`                                | Save a full-page screenshot as evidence                        |

- **Targets**: exactly one of `role` (with optional `name`), `text`, `label`, `alt` or `css`, plus an optional `frame`.
- **Timeouts**: every step but `screenshot` takes `timeoutMs` (100 to 180000). Defaults: 5 s for elements, 15 s for page loads.
- **Prove the behavior**: expect what only shows when it worked, such as the exact success message. A field label proves nothing.

## Continuing a case

`"continue": true` starts a case on the page the case before it ended on, instead of the job URL. Use it to check what an earlier case made, one check per case.

```json
{
  "id": "no-sample-logos",
  "title": "The portfolio shows no sample client logos",
  "continue": true,
  "steps": [{ "action": "expectNoText", "text": "Acme" }]
}
```

- A continuing case runs even when the case before it failed.
- The first case of a job cannot continue.

## Test accounts

A job runs signed in with `account`: a label, or `{ "label": "paid-user", "about": "Pro plan, paying monthly" }`. Without it, a run starts signed out.

### Start the job
Nothing starts, and you're asked to sign in, when the account has no saved session for this origin, its session was saved for another origin (staging instead of localhost), or all its cookies expired. Over MCP the reply gives a link to a live view of the browser; the CLI exits with code 9 and prints the command:

```sh
npx -y screw-bugs@latest accounts sign-in trial-user --url http://localhost:3000 --about "On a 14-day trial"
```

### Sign in once
Open the live view, sign in as that user and press **Save sign-in**. What you type is never logged, recorded or saved; only the app's cookies and storage are kept.

### Run again
Every later run with that account starts signed in.

- Over MCP: call `start_run` once with `waitSeconds: 0` to get the link and show it to the user, then again with `waitSeconds` (up to 600) to wait for **Save sign-in** and start.
- Session stopped working sooner (the run lands on a sign-in page)? Send `{ "label": "trial-user", "renew": true }` once. It doesn't ask again for 10 minutes after a save.

Sessions live in `.screw-bugs/accounts/<label>.json` (mode 0600), listed in `.screw-bugs/accounts.json`. For Cloud runs, see [Test accounts](/cloud/test-accounts.md).

## Full reference

The README has every detail:

- The screw-bugs README, sections "Jobs, cases and steps", "Waiting and scrolling", "Frames", "Images and links", "Uploads", "Continuing a case" and "Test accounts".
- `npx -y screw-bugs@latest schema job` prints the full JSON Schema, with every limit.
- The schema itself: `packages/core/src/schema/job.ts` (screw-bugs)

**Next:** [Reports](/screw-bugs/reports.md)