# when

The `when` step.

Runs `do` when a condition holds and `else`, if given, when it does not.

Type: `condition`

## Keys

| Key | Type | Description |
|---|---|---|
| `when.do` | `any[]` | The steps run when the condition holds, at least one. |
| `when.else` | `any[]` | The steps run when the condition does not hold, at least one when present. |

Every step also takes the [common step keys](https://docs.kaab.ist/reference/dsl/steps#common-keys): `expect`, `id`, `if`, `name`, `on_error`, `optional`, `retry`, `side_effect`, `timeout_ms`, `x_kaab`.

## Example

```json
{
  "id": "otp",
  "when": {
    "visible": "#otp"
  },
  "do": [
    {
      "id": "ask-otp",
      "await_input": {
        "name": "otp",
        "prompt": "SMS code",
        "ttl": "5m",
        "expires": "24h",
        "collect": "hosted",
        "hosted": {
          "notify": "email",
          "to": "{{inputs.email}}"
        }
      }
    },
    {
      "id": "fill-otp",
      "fill": "#otp",
      "value": "{{vars.otp}}"
    },
    {
      "id": "confirm",
      "click": {
        "role": "button",
        "name": "Verify"
      },
      "side_effect": true,
      "expect": {
        "landmark": "logged_in"
      }
    }
  ]
}
```

From the contract fixture `login-2fa-checkpoint-report`, a program the test suite validates.
