# Momentic V2 format reference

Use this reference when the high-level Momentic skill does not cover the YAML
shape you need. The JSON schemas are for editor validation and autocomplete;
this file is the compact authoring reference for coding agents.

## Compatibility

| Feature              | Minimum version                             |
| -------------------- | ------------------------------------------- |
| Web while loops      | `momentic@3.8.0`                            |
| Run assertions       | `momentic@3.33.0`                           |
| Web `fill` alias     | `momentic@3.41.0`                           |
| Bare AI-action goals | `momentic@3.52.0`, `momentic-mobile@1.28.0` |
| Mobile while loops   | `momentic-mobile@1.26.0`                    |

Use the explicit `act:` form when a project may run an older CLI. Bare AI-action
goals always select AI action V3.

## File types

Browser test:

```yaml
fileType: momentic/test/v2
id: opal-river-sparrow
url: https://example.com
steps: []
```

Browser module:

```yaml
fileType: momentic/module/v2
id: indigo-cedar-bridge
name: Login
steps: []
```

Mobile test:

```yaml
fileType: momentic/mobile-test/v2
id: sunlit-forest-window
platform: android
steps: []
```

Mobile modules use `fileType: momentic/mobile-module/v2`; their `platform`
defaults to `android`. IDs must be unique within the Momentic organization.
Momentic creation tools, including MCP, generate readable slugs with a variable
number of words. A hand-authored ID can be any stable lowercase kebab-case slug
up to 36 characters. Legacy UUID IDs remain valid. The serializer normally
omits `version`, default browser type, and default viewport metadata.

## Test sections

Tests can contain `before`, `steps`, and `after`. Modules contain `steps`.
Do not add legacy `SECTION` steps to V2 YAML.

```yaml
before:
  - navigate: /login
steps:
  - type:
      text: "{{ env.USER_EMAIL }}"
      into: Email
after:
  - authSave
```

Browser tests can also define run assertions, which Momentic evaluates against
the run recording:

```yaml
runAssertions:
  - A Saved confirmation appears after the form is submitted
```

## Step shapes

Each list item is exactly one step. A preset step can be a bare command, a
command with a scalar payload, or a command with detailed options:

```yaml
- refresh
- click: Submit
- click:
    on: Submit
    timeout: 5000
```

Detailed options must be nested under the command key. Do not write sibling
options beside a scalar command:

```yaml
# Invalid
- click: Submit
  retries: 1
```

Detailed steps can use `saveAs`, `retries`, `skipped`, and `comment`.
Preserve existing metadata unless the requested change requires updating it.

## AI actions

A multi-word bare string is an AI action V3 goal on supported CLI versions:

```yaml
- Add a Gravity Blanket to the cart and open checkout
```

Known platform-specific one-word strings such as `refresh` on web and `killApp`
on mobile remain preset steps. Unknown one-word strings are invalid, which
prevents misspelled preset commands from silently becoming AI actions.

Use `act` when the action needs options:

```yaml
- act:
    goal: Complete checkout as a guest
    version: "3"
    precondition: The cart contains one Gravity Blanket
    postcondition: An order confirmation number is visible
    cache: false
```

`precondition`, `postcondition`, and `cache` apply to V3. A postcondition
states the durable product outcome that must hold before the action passes.
The shorthand and explicit forms have identical execution and cache semantics.
`advanced.aiActionShorthand` only controls which form Momentic writes when it
serializes a V3 action; it does not control whether shorthand can be parsed.

## Type and fill

`type` dispatches keyboard events and can set a delay or clear strategy. `fill`
replaces the input value in one operation without per-keystroke events.

```yaml
- type:
    text: ada@example.com
    into: Email
    delay: 25
    clear: inputs
- fill:
    text: secret-password
    into: Password
```

Both commands support a scalar payload when the intended input already has
focus:

```yaml
- type: hello world
- fill: replacement value
```

## Conditionals and while loops

Place the assertion directly inside `if`; V2 conditionals do not have a
`condition` wrapper or an `else` branch:

```yaml
- if:
    assert: The cart is empty
    then:
      - click: Add to cart
```

A while loop has a `do` list plus an inline assertion, `maxIterations`, or
both:

```yaml
- while:
    assert: A Load more button is visible
    do:
      - click: Load more
    maxIterations: 10
```

When there is no assertion, `maxIterations` is required. Keep loops finite.

## Modules and parameters

Invoke a module with a scalar path when it has no inputs:

```yaml
- module: ../modules/login.module.yaml
```

Use the detailed form for inputs. Each input can be a shorthand string,
`{ string }`, or `{ javascript }`:

```yaml
- module:
    path: ../modules/login.module.yaml
    inputs:
      EMAIL: "{{ env.USER_EMAIL }}"
      TENANT:
        string: acme
      NOW:
        javascript: return new Date().toISOString()
```

Prefer object-form module parameter declarations:

```yaml
parameters:
  - name: EMAIL
  - name: TENANT
    default:
      string: acme
    enum: [acme, globex]
```

The legacy bare-string `parameters`, `defaultParameters`, and
`parameterEnums` fields remain valid for backward compatibility.

## File references

Relative file references resolve from the YAML file containing the step. A path
inside a module is relative to that module, not the top-level test.

```yaml
- javascript: ./scripts/setup.js
- authLoad: ./auth-state.json
- authSave: ./auth-state.json
- module: ../modules/login.module.yaml
```

Do not use absolute paths, `~`, or `file://` for local V2 references.

## Browser preset steps

| Key                       | Purpose                                                                                                                                                               |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `click`                   | Click on an element on the page.                                                                                                                                      |
| `doubleClick`             | Double-click an element on the page.                                                                                                                                  |
| `rightClick`              | Right-click an element on the page.                                                                                                                                   |
| `hover`                   | Hover over an element on the page. Automatically scrolls the element into view, so can double as a scroll-to.                                                         |
| `blur`                    | Remove focus from an element on the page.                                                                                                                             |
| `focus`                   | Focus an element on the page.                                                                                                                                         |
| `type`                    | Type the specified text into an element.                                                                                                                              |
| `fill`                    | Replace an input's value in one operation without per-keystroke events.                                                                                               |
| `select`                  | Select an option from a native HTML `<select>` element.                                                                                                               |
| `dragAndDrop`             | Click and drag an element to another location.                                                                                                                        |
| `mouseDrag`               | Drag the mouse by pixel deltas from a starting point.                                                                                                                 |
| `press`                   | Press one or more keyboard keys (Playwright key syntax).                                                                                                              |
| `keyDown`                 | Hold down one or more keyboard keys.                                                                                                                                  |
| `keyUp`                   | Release one or more keyboard keys.                                                                                                                                    |
| `navigate`                | Navigate to the specified URL.                                                                                                                                        |
| `newTab`                  | Create and switch to a new tab in the browser.                                                                                                                        |
| `switchTab`               | Switch to a different tab in the browser.                                                                                                                             |
| `closeTab`                | Close a tab, or the current tab if no selector is provided.                                                                                                           |
| `goBack`                  | Go back in browser history.                                                                                                                                           |
| `goForward`               | Go forward in browser history.                                                                                                                                        |
| `refresh`                 | Refresh the active page (does not clear cookies or storage).                                                                                                          |
| `scrollUp`                | Scroll up by a specified number of pixels.                                                                                                                            |
| `scrollDown`              | Scroll down by a specified number of pixels.                                                                                                                          |
| `scrollLeft`              | Scroll left by a specified number of pixels.                                                                                                                          |
| `scrollRight`             | Scroll right by a specified number of pixels.                                                                                                                         |
| `wait`                    | Wait for the specified number of milliseconds.                                                                                                                        |
| `assert`                  | Ask AI to verify whether a statement is true on the page.                                                                                                             |
| `assertVisually`          | Ask AI to verify a statement using only the visible screenshot.                                                                                                       |
| `checkPageContains`       | Assert the page contains the given text.                                                                                                                              |
| `checkPageDoesNotContain` | Assert the page does NOT contain the given text.                                                                                                                      |
| `extract`                 | Ask AI to extract structured data from the page.                                                                                                                      |
| `cookie`                  | Set a cookie that persists throughout the browser session.                                                                                                            |
| `localStorage`            | Set a localStorage entry for the active origin.                                                                                                                       |
| `request`                 | Make an HTTP request to a URL.                                                                                                                                        |
| `graphqlRequest`          | Make a GraphQL request to a URL.                                                                                                                                      |
| `javascript`              | Run JavaScript in the browser or Node.js.                                                                                                                             |
| `header`                  | Set an HTTP request header on subsequent network requests.                                                                                                            |
| `mock`                    | Mock network responses for matching requests.                                                                                                                         |
| `removeRouteMock`         | Remove a previously installed `mock` by its key.                                                                                                                      |
| `waitForUrl`              | Wait for the active page URL to match a pattern.                                                                                                                      |
| `waitForUrlNotToMatch`    | Wait until the active page URL stops matching a pattern.                                                                                                              |
| `dialog`                  | Specify how the next native browser dialog is handled.                                                                                                                |
| `fileUpload`              | Upload a file when the next native file picker is opened. Path can be a plain local path relative to the YAML file containing this step or a publicly accessible URL. |
| `copy`                    | Copy a value to the browser clipboard.                                                                                                                                |
| `paste`                   | Paste the browser clipboard contents into the focused element.                                                                                                        |
| `captcha`                 | Solve a CAPTCHA on the page. Only available on the Momentic dashboard; may take up to 60 seconds.                                                                     |
| `visualDiff`              | Compare a screenshot of the page or a specific element to a baseline image.                                                                                           |
| `offline`                 | Take the browser offline.                                                                                                                                             |
| `online`                  | Restore the browser to online mode after `offline`.                                                                                                                   |
| `registerRequestListener` | Register a listener for matching network requests, retrievable via `awaitListener`.                                                                                   |
| `awaitListener`           | Wait for a previously registered listener to fire.                                                                                                                    |
| `recordRequests`          | Record matching network requests under a key.                                                                                                                         |
| `getRecordedRequests`     | Retrieve previously recorded requests by key.                                                                                                                         |
| `authLoad`                | Load (or clear) browser authentication state. Provide an empty path to clear.                                                                                         |
| `authSave`                | Save browser authentication state (cookies, localStorage) to a JavaScript object or file.                                                                             |

Dynamic `checkElement...` aliases cover element existence, visibility,
enabled/editable/focused state, text content, attributes, tag names, and styles.
Use the generated JSON schema or command reference for the exact alias and
payload fields.

## Mobile preset steps

| Key                         | Purpose                                                                                                                                                                                                                             |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tap`                       | Tap a target in the mobile app.                                                                                                                                                                                                     |
| `type`                      | Type text into a mobile target or the focused input.                                                                                                                                                                                |
| `press`                     | Press a physical mobile device button.                                                                                                                                                                                              |
| `pressKey`                  | Press a mobile keyboard key.                                                                                                                                                                                                        |
| `openApp`                   | Open an installed mobile app.                                                                                                                                                                                                       |
| `killApp`                   | Terminate the currently configured mobile app.                                                                                                                                                                                      |
| `openNotifications`         | Open the Android notification drawer.                                                                                                                                                                                               |
| `swipe`                     | Swipe in a direction within the mobile app.                                                                                                                                                                                         |
| `scrollTo`                  | Scroll until a mobile target is visible.                                                                                                                                                                                            |
| `assert`                    | Ask AI to verify whether a statement is true in the mobile app.                                                                                                                                                                     |
| `extract`                   | Ask AI to extract structured data from the mobile app.                                                                                                                                                                              |
| `checkScreenContains`       | Assert the mobile screen contains the given text.                                                                                                                                                                                   |
| `checkScreenDoesNotContain` | Assert the mobile screen does NOT contain the given text.                                                                                                                                                                           |
| `dragAndDrop`               | Drag from one mobile target to another.                                                                                                                                                                                             |
| `javascript`                | Run JavaScript in the mobile test runtime.                                                                                                                                                                                          |
| `request`                   | Make an HTTP request from the mobile test runtime.                                                                                                                                                                                  |
| `wait`                      | Wait for the specified number of milliseconds.                                                                                                                                                                                      |
| `addFile`                   | Copy a local file or URL into the mobile device or simulator.                                                                                                                                                                       |
| `setCamera`                 | Play a video file as the camera feed of a Momentic-hosted iOS simulator.                                                                                                                                                            |
| `clearCamera`               | Stop camera video playback and restore the default simulator camera.                                                                                                                                                                |
| `setMicrophone`             | Play an audio file as the microphone input of a Momentic-hosted iOS simulator.                                                                                                                                                      |
| `clearMicrophone`           | Stop microphone audio playback.                                                                                                                                                                                                     |
| `installApp`                | Install an app on the Android or iOS device.                                                                                                                                                                                        |
| `uninstallApp`              | Uninstall an Android app by package name.                                                                                                                                                                                           |
| `toggleSettings`            | Toggle an Android device setting.                                                                                                                                                                                                   |
| `visualDiff`                | Compare a full-screen screenshot against a golden image stored locally. The golden file is created on first run; subsequent updates require running with `--update-golden-files`. Only supported when running mobile tests locally. |
| `rotate`                    | Rotate the mobile device or simulator.                                                                                                                                                                                              |
| `adb`                       | Run an Android Debug Bridge command.                                                                                                                                                                                                |
| `appium`                    | Run an Appium script against the active mobile session.                                                                                                                                                                             |
| `debugState`                | Capture the current mobile debug state.                                                                                                                                                                                             |

## Cache and IDs

V2 YAML omits volatile step IDs, command IDs, locator caches, and execution
artifacts. Do not add them manually. Momentic restores internal identity and
compatible execution caches when it loads the file.

## Validation

After direct YAML edits, run:

```bash
npx momentic lint path/to/file.test.yaml
npx momentic lint path/to/file.module.yaml
```

Lint is authoritative because it uses Momentic's parser and project context.
The JSON schema is an editor aid and intentionally cannot express every
cross-field rule.

Switch to the MCP/browser workflow when you need live page state, locator
discovery, timing validation, or a non-idempotent reproduction.
