> ## Documentation Index
> Fetch the complete documentation index at: https://piyushvyas.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Workflows

> Record, replay, and manage deterministic browser workflows. Capture a sequence of BAP commands and replay them with parameter substitution.

# Workflows

Record a sequence of BAP commands and replay them later. Workflows are saved as YAML and support parameter substitution.

## Record a Workflow

<Steps>
  <Step title="Start recording">
    ```bash theme={null}
    bap workflow record qa-checkout
    ```

    All subsequent BAP commands will be captured.
  </Step>

  <Step title="Run your commands normally">
    ````bash bap goto https://shop.example.com --observe bap act fill:label:"Search"="headphones" theme={null}
    press:Enter bap click role:link:"Sony WH-1000XM5" bap act click:role:button:"Add to Cart" ```
    </Step>

    <Step title="Stop recording">
      ```bash
      bap workflow stop
    ````

    Saves the workflow as YAML to `~/.bap/workflows/qa-checkout.yml`.
  </Step>
</Steps>

## Run a Workflow

```bash theme={null}
bap workflow run qa-checkout
```

With parameter substitution:

```bash theme={null}
bap workflow run qa-checkout --param search=speakers --param product="JBL Flip 6"
```

<ParamField path="name" type="string" required>
  Name of the saved workflow to run.
</ParamField>

<ParamField path="--param" type="string" repeatable>
  Parameter substitution in `key=value` format. Can be specified multiple times.
</ParamField>

Output shows pass/fail status for each step:

```
Running workflow: qa-checkout
4 steps

  PASS Step 1: goto https://shop.example.com  120ms
  PASS Step 2: act fill:label:"Search"="headphones" press:Enter  85ms
  PASS Step 3: click role:link:"Sony WH-1000XM5"  230ms
  PASS Step 4: act click:role:button:"Add to Cart"  95ms

PASS -- 4 passed, 0 failed (530ms)
```

## List Workflows

```bash theme={null}
bap workflow list
```

## Macros

Macros are reusable workflow fragments. Record them the same way:

<CodeGroup>
  ```bash Record a macro theme={null}
  bap workflow macro login
  bap goto https://app.example.com/login
  bap act fill:label:"Email"="user@test.com" \
          fill:label:"Password"="pass" \
          click:role:button:"Sign in"
  bap workflow macro stop
  ```

  ```bash List macros theme={null}
  bap workflow macros
  ```
</CodeGroup>

Reference macros in workflows with `macro: <name>`.

## Optimized Execution with `bap run`

For fastest execution, use `bap run` instead of `bap workflow run`. It compiles workflows into fused batches:

```bash theme={null}
bap run qa-checkout --param search=speakers
```

See the [run command](/cli/run) for details on compilation and cache warming.

<Tip>
  `bap workflow run` executes steps sequentially as recorded. `bap run` compiles them into optimized
  batches with fusion, resulting in fewer server calls.
</Tip>
