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

# Run iOS UI checks in CI on every pull request

> Run your saved checks on every pull request, on GitHub's hosted Mac or a Mac of yours, and get one comment with each verdict.

`mobster ci` tests the screens each pull request changed, on simulators and on any iPhone plugged into the runner. Mobster charges nothing per run or per device.

## Test every pull request

You need one saved check in `.mobster/checks`. [Test your app](https://docs.mobster.dev/quickstart/test.md) writes your first.

**1. Write the workflow**

From your project's folder, with the `mobster` command [from PyPI](https://docs.mobster.dev/quickstart/cli.md):

```sh theme={"theme":"css-variables"}
mobster ci init
```

It prints `Wrote .github/workflows/mobster.yml.` and the two steps left. The workflow runs on `macos-15`, the Mac GitHub hosts, and installs `mobster` from PyPI. It needs no Mac of yours, no account and no token. GitHub's hosted Mac is free in a public repository, and in a private one GitHub bills its macOS minutes to your account. [GitHub Actions](https://docs.mobster.dev/ci/github-hosted.md) has the workflow line by line.

**2. Add your key**

Add `ANTHROPIC_API_KEY` as a repository secret if a check has steps. A launch-only check needs no key.

**3. Open a pull request**

Commit `.github/workflows/mobster.yml`, push the branch and open a pull request.

Mobster comments on the pull request with each check's verdict, what it expected and found, and the command that runs a failure again. Each push updates the same comment.

## Test on your own iPhone

> [!NOTE]
>
> You get this in the next release, not in Mobster for Mac 0.4.0 or Mobster CLI 0.4.4.

GitHub's hosted Mac has no iPhone. To test on yours, make a Mac of yours the runner.

**1. Write the workflow**

From your project's folder:

```sh theme={"theme":"css-variables"}
mobster ci init --self-hosted
```

It reads the `origin` remote to pick GitHub or GitLab. In a project with no checks yet, it prints:

```text theme={"theme":"css-variables"}
Wrote .github/workflows/mobster.yml.

Next:
  1. On the Mac that runs the checks: mobster ci doctor
  2. Register it as a self-hosted runner with the label mobster: https://docs.mobster.dev/ci/mac-runner
  3. Add ANTHROPIC_API_KEY as a repository secret, for checks with steps.
  4. Commit the file and open a pull request.

This project has no checks yet. `mobster test pr` drafts one for each screen a PR changes, and `mobster test record` turns a finished task into one.
```

* On GitLab it writes the `mobster` job in `.gitlab-ci.yml`, for a Mac of yours with or without `--self-hosted`. Follow [GitLab CI](https://docs.mobster.dev/ci/gitlab.md) from here.
* With no `origin` remote, pass the host: `mobster ci init --self-hosted --host github` or `mobster ci init --host gitlab`.
* `--device "Test iPhone"` also tests on an iPhone plugged into the runner ([Your iPhone in CI](#your-iphone-in-ci)), so it writes this workflow without `--self-hosted`.
* An existing workflow file stays as it is. `--force` replaces it.

**2. Check the Mac**

The runner needs the `mobster` command: [from PyPI](https://docs.mobster.dev/quickstart/cli.md), or in a signed-in [Mobster for Mac](https://mobster.dev/download). On that Mac:

```sh theme={"theme":"css-variables"}
mobster ci doctor
```

It changes nothing. On a runner with Mobster for Mac and no iOS Simulator runtime yet, it prints:

```text Output theme={"theme":"css-variables"}
✓ Apple silicon              this Mac is arm64
✓ Xcode                      Xcode 26.4
✗ iOS Simulator runtime      none installed
                             Run `xcodebuild -downloadPlatform iOS`.
✓ Mobster for Mac            in Applications
✓ Mobster plan               active on this Mac
✓ System sleep               never
! Restart after a power cut  off
                             Run `sudo pmset -a autorestart 1`.
✓ Automatic login            as ci
✓ Runner service             GitHub Actions runner
✓ Free disk                  212 GB
✓ Phones this runner allows  none: checks run on simulators only

Fix the rows marked ✗, then run `mobster ci doctor` again.
```

A `!` row is a recommendation and doesn't stop a job.

**3. Register the runner**

Register the Mac as a self-hosted runner with the label `mobster`. [A Mac as your runner](https://docs.mobster.dev/ci/mac-runner.md) has the steps, Mac mini setup included.

**4. Add your key and open a pull request**

Add `ANTHROPIC_API_KEY` as a repository secret if a check has steps. Commit the workflow file and open a pull request. The job posts [the comment](#the-comment).

## The workflow

> [!NOTE]
>
> You get this in the next release, not in Mobster for Mac 0.4.0 or Mobster CLI 0.4.4.

`mobster ci init --self-hosted` writes this file for a Mac of yours. It runs on a runner with the `mobster` label, so your other jobs stay on hosted runners. `$MOBSTER` is the `mobster` command inside [Mobster for Mac](https://mobster.dev/download).

```yaml .github/workflows/mobster.yml theme={"theme":"css-variables"}
# Mobster checks on every pull request, on a Mac of yours (https://docs.mobster.dev/ci).
# The runner needs Mobster for Mac in Applications. On that Mac, `mobster ci doctor` says what's missing.
name: mobster
on: pull_request
permissions:
  contents: write        # store frames for your failed checks under refs/mobster/ (https://docs.mobster.dev/ci#frames-in-the-comment)
  pull-requests: write   # the one comment Mobster keeps up to date
  checks: write          # post the Mobster check with the verdict
concurrency:
  group: mobster-${{ github.event.pull_request.number }}
  cancel-in-progress: true
env:
  MOBSTER: /Applications/Mobster.app/Contents/MacOS/mobster-agent
jobs:
  checks:
    runs-on: [self-hosted, macOS, mobster]
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0   # the diff needs the base branch
          persist-credentials: false   # keep the token out of .git/config for your build steps
      - name: Restore recorded steps
        id: replay
        uses: actions/cache/restore@v4
        with:
          path: .mobster/cache/replay   # checkout deletes it; steps recorded in earlier runs replay with no model
          key: mobster-replay-${{ github.run_id }}-${{ github.run_attempt }}
          restore-keys: |
            mobster-replay-
      - name: Test what this PR changed
        run: |
          "$MOBSTER" ci run
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}   # only checks with steps use it
      - name: Save recorded steps
        if: always()   # when a check fails, keep what the checks that passed recorded
        uses: actions/cache/save@v4
        with:
          path: .mobster/cache/replay
          key: ${{ steps.replay.outputs.cache-primary-key }}
      - name: Upload the report
        id: upload
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: mobster-report
          path: .mobster/ci/
          include-hidden-files: true
          retention-days: 14
          if-no-files-found: ignore
      - name: Comment on the PR
        if: always()
        run: |
          "$MOBSTER" ci comment
        env:
          GITHUB_TOKEN: ${{ github.token }}
          MOBSTER_ARTIFACT_URL: ${{ steps.upload.outputs.artifact-url }}
```

With `mobster` from PyPI, the workflow runs `uvx --python 3.12 --from mobster-cli==0.4.4 mobster` where this one runs `"$MOBSTER"`, on a runner with [uv](https://docs.astral.sh/uv/) (`brew install uv`). It asks for `contents: read` and `pull-requests: write`, and its comment step keeps the comment and the job summary only.

1. `mobster ci run` fetches the base branch and runs [`mobster test pr`](https://docs.mobster.dev/testing#test-a-pull-request) with `--video`. It builds the app, runs the saved checks that cover the changed screens, and drafts a check for each changed screen none covers. When it picks no check and the pull request changed a file that feeds the app, it runs every check. The step fails when a check fails, can't run or needs review ([exit codes](https://docs.mobster.dev/testing.md#exit-codes)).
2. The upload keeps `.mobster/ci/` as the job's artifact: `junit.xml`, `pr.json`, the HTML report, frames, GIFs and videos.
3. `mobster ci comment` creates the pull request comment, or updates the one from an earlier push, and writes the job summary. It never fails your job.

`mobster ci comment` also posts the check `Mobster` (next release) on the head commit with the job's token (`checks: write`): the verdict is its conclusion ([The check](https://docs.mobster.dev/ci/github-app.md#the-check)), and the comment is its summary.

The two cache steps keep the steps your checks recorded, so later runs replay them with no model. `actions/checkout` deletes `.mobster/cache/replay`, so the job restores it from GitHub's cache before the checks and saves it after them, even when a check fails. A pull request starts from its own earlier runs, or else from a run on your default branch, such as [every check on a schedule](#every-check-not-only-the-changed-screens). It never reads another pull request's cache.

## The comment

Each push updates the same comment:

```markdown theme={"theme":"css-variables"}
### Mobster checks: 11 passed, 1 failed

Changed screens: `PaywallView`, `SettingsView`, at `a6d8d39` on iPhone 17 Pro, iOS 26.4

<table><tr>
<td width="260"><img src="https://github.com/your-org/your-app/blob/…/001-01-the-paywall-shows-three-plans-iphone-17-pro-ios-26-4.jpg?raw=true" width="240" alt="The screen this check was judged on"></td>
<td>

**Failed: The paywall shows three plans** on iPhone 17 Pro, iOS 26.4

Its last step was Scroll to the plans. Expected text “Choose your plan”: not on screen; closest: "Choose a plan".

This PR removed “Choose your plan” at `App/PaywallView.swift:12`. The check states it at `.mobster/checks/paywall.yaml:9`.

Run it again: `mobster test .mobster/checks/paywall.yaml --sim 'iPhone 17 Pro@iOS 26.4'`

</td>
</tr></table>
...
<details><summary>Repro: The paywall shows three plans (failed, assertion failed on the final screen)</summary>
...
</details>

[Report, frames and GIFs](…)
```

* A run on one device names it once, after the commit. A run on several gives the table a Device column. A check that replayed says so beside its verdict: **Passed, replayed**.
* Up to 3 checks that didn't pass lead the comment: what the check expected and found, the source line your pull request changed, the check line, and the command that runs it again.
* Up to 5 get a folded repro: the device, the deep link, the steps, which side to look at (the app, the check or the environment), the requests and last log lines of the failing step, its media, and the command that runs it on the same device.
* Typed text, email addresses and phone numbers in a step show as `•••`.
* The frames, GIFs and videos link to the uploaded report. GitHub doesn't show images from workflow artifacts inside a comment, so the frame itself shows only when `mobster ci comment` stores it in your repository ([Frames in the comment](#frames-in-the-comment)).
* The comment ends with "Tested with Mobster", linked to mobster.dev (next release). `mobster ci run --no-tested-with` leaves it out.

## Frames in the comment

> [!NOTE]
>
> You get this in the next release, not in Mobster for Mac 0.4.0 or Mobster CLI 0.4.4.

In GitHub Actions, `mobster ci comment` stores the frames of the checks that lead your comment in your repository, and the comment shows them.

* Mobster writes 1 commit with no parent under `refs/mobster/frames/<YYYYMMDD>/<head commit>/<frames commit>`, through the GitHub API with the job's token. No branch list shows the ref. Mobster never moves an existing ref, and stores nothing when every check passes.
* Only people who can read the repository can open the frames.
* `--frames auto` stores simulator frames only, and only when the job's event says the repository is private. An internal repository counts as public. `--frames on` also stores frames in public repositories and frames from your iPhone. `--frames off` stores none.
* GitHub still serves a commit by its SHA after you delete its ref. A frame stored in a public repository stays public, and making a private repository public publishes every frame in it.
* The job needs `contents: write`. The workflow checks out with `persist-credentials: false`, so the token isn't left in `.git/config` for the steps that build your pull request, though they run in the same job. If your repository gives write tokens to pull requests from forks, set `contents: read` and run `mobster ci comment --frames off`.
* Frames are stored only on github.com. The Mobster test action links them in the report instead.
* `git ls-remote origin 'refs/mobster/frames/*'` lists the refs, and `git push origin --delete <ref>` deletes one.

## Line annotations

> [!NOTE]
>
> You get this in the next release, not in Mobster for Mac 0.4.0 or Mobster CLI 0.4.4.

In GitHub Actions, `mobster ci comment` and the Mobster test action print 1 annotation for each failure, warning or notice. Source-line annotations also show in the pull request's **Files changed** tab:

```text theme={"theme":"css-variables"}
Error: App/PaywallView.swift#L12
The paywall shows three plans failed on iPhone 17 Pro, iOS 26.4
Its last step was Scroll to the plans. Expected text “Choose your plan”: not on screen; closest: "Choose a plan". This PR removed “Choose your plan” on this line. The check states it at .mobster/checks/paywall.yaml:9. Run it again: mobster test .mobster/checks/paywall.yaml --sim 'iPhone 17 Pro@iOS 26.4'
```

[Mobster Checks](https://docs.mobster.dev/ci/github-app.md#line-annotations) lists which result gets which annotation, and where. These need no token or permission, and pull requests from forks get them too. GitHub Actions keeps 10 of each kind per step. Text from your app's screen is escaped, so it can't end an annotation or start another workflow command. GitLab and other hosts get none.

## Your iPhone in CI

A pull request can edit the workflow file, so a phone named only there doesn't reach it. The runner's owner lists the phones it may test, and any TestFlight apps, in the runner's `.env` file, which no pull request can change:

```sh ~/actions-runner/.env theme={"theme":"css-variables"}
MOBSTER_RUNNER_DEVICES=Test iPhone
MOBSTER_RUNNER_TESTFLIGHT=com.example.yourapp
```

```yaml theme={"theme":"css-variables"}
      - name: Test what this PR changed
        run: |
          "$MOBSTER" ci run --device "Test iPhone" --testflight com.example.yourapp
```

* A `--device` or `--testflight` the runner doesn't list stops the job before a check runs. Put these flags before `--`. Restart the runner after you change `.env`: in `~/actions-runner`, run `./svc.sh stop && ./svc.sh start`.
* On a phone, a check drives only builds you installed: the device build from this job, a build Xcode installed, or a TestFlight build you named.
* Steps stay in your app, and never send, buy, post or delete on the phone.
* For several phones, list each in `MOBSTER_RUNNER_DEVICES` and pass each with `--device`. Every check runs on every phone. Add `--spread` after `--` to run each check once, on whichever phone is free ([Share the checks between phones](https://docs.mobster.dev/testing.md#share-the-checks-between-phones)).
* Keep the phone unlocked, awake and charging. [A Mac as your runner](https://docs.mobster.dev/ci/mac-runner.md) has the settings.

> [!WARNING]
>
> A self-hosted runner runs the code in each pull request. Don't use one on a public repository that takes pull requests from forks: GitHub's [security hardening guide](https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#hardening-for-self-hosted-runners) explains why. Use a test phone signed in to a test account.

## Use the Mobster test action

`RadishSoftware/test-action` runs `mobster test pr`, uploads the report and keeps the comment in one step. It uses the runner's `mobster`, or the one in [Mobster for Mac](https://mobster.dev/download). On GitHub's hosted Mac (next release), write `runs-on: macos-15`, and it installs `mobster` from PyPI with [uv](https://docs.astral.sh/uv/).

```yaml .github/workflows/mobster.yml theme={"theme":"css-variables"}
name: mobster
on: pull_request
permissions:
  contents: read
  pull-requests: write
jobs:
  test:
    runs-on: [self-hosted, macOS, mobster]
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: RadishSoftware/test-action@v1
        with:
          scheme: YourApp
```

| Input | What it does |
| - | - |
| `base` | The branch the changed screens are measured against. Default: the pull request's base branch. |
| `sim` | Simulator device types, one per line, such as `iPhone 17 Pro@iOS 26.4`. Default: each check's own. |
| `device` | iPhones on this runner, one per line, by their names in `mobster devices`. The runner's `MOBSTER_RUNNER_DEVICES` must list each. |
| `testflight` | With `device`, the bundle ID of your app's TestFlight build. The runner's `MOBSTER_RUNNER_TESTFLIGHT` must list it. |
| `build` | Build the app before testing it. Default: `true`. |
| `scheme`, `project` | The Xcode scheme and the `.xcodeproj` or `.xcworkspace` to build. Default: the only one. |
| `drafts` | Checks for changed screens no check covers: `run`, `write` or `off`. Drafts never fail the pull request. Default: `run`. |
| `args` | More `mobster test pr` flags, such as `--retries 2 --parallel 2`. |
| `working-directory` | The folder that holds `.mobster`. Default: `.`. |
| `comment` | Keep one comment on the pull request. The job summary has the verdict either way. Default: `true`. |
| `tested-with` (next release) | End the comment with a "Tested with Mobster" line. Default: `true`. |
| `fail-on-failure` | Fail your job when a check fails, can't run or needs review. Default: `true`. |
| `artifact-name`, `retention-days` | The uploaded report's name and how many days GitHub keeps it. Defaults: `mobster-report` and `14`. |
| `github-token` | The token that writes the comment. It needs `pull-requests: write`. Default: the job's token. |

It sets four outputs: `exit-code` (0 passed, 1 failed, 2 needs review, 3 couldn't run), `headline`, `report-dir` and `artifact-url`.

## Share the report with your team

With the [Team plan](https://docs.mobster.dev/team.md), the comment can link your team's sealed hosted report instead of the job's artifacts ([Share a report with your team](https://docs.mobster.dev/testing.md#share-a-report-with-your-team)).

1. An Owner or Admin makes an upload key with `POST /api/orgs/$ORG/upload-keys` and `{"name": "…"}`. It prints the secret once, `mtk_…`. Put your team id and a colon in front of it: `<team id>:mtk_…`.
2. Add it to the repository's secrets as `MOBSTER_TEAM_KEY`, and pass it in the test step's `env` beside `ANTHROPIC_API_KEY`.

With `MOBSTER_TEAM_KEY` set, `mobster ci run` adds `--share`, and `mobster ci comment` links the hosted report on GitHub and GitLab. The link holds the report's key after the `#`. Opening it needs the link and a signed-in account in the team. An upload key only uploads, and an Owner or Admin revokes it with `DELETE /api/orgs/$ORG/upload-keys/$KEY`, where `$KEY` is the key's id from `GET /api/orgs/$ORG/upload-keys`.

> [!NOTE]
>
> You get this in the next release, not in Mobster for Mac 0.4.0 or Mobster CLI 0.4.4.

In CI, `--share` uploads only when the CI host says the repository is private: on GitHub Actions, the event's `repository.private` is `true`, and on GitLab, `CI_PROJECT_VISIBILITY` is `private`. Otherwise the job's log says why, and the comment links the job's artifacts. To share anyway, set `MOBSTER_SHARE_LINK_IN_CI: "1"` in the step's `env`.

## Add flags and XCTest

Flags after `--` go to `mobster test pr`. `--xctest` adds your unit tests, which join the checks in the comment, the JUnit file and the report ([Your XCTest targets](https://docs.mobster.dev/testing.md#your-xctest-targets)):

```yaml theme={"theme":"css-variables"}
        run: |
          "$MOBSTER" ci run --sim "iPhone 17 Pro" --sim "iPhone SE (3rd generation)" -- --parallel 2 --retries 2 --xctest
```

`--no-video` turns the screen recordings off. [CLI: mobster ci](https://docs.mobster.dev/reference/cli/ci.md) lists every flag.

## Read the results in other tools

`.mobster/ci/junit.xml` works with any JUnit reader. GitLab shows it in the merge request. On GitHub, with [test-reporter](https://github.com/dorny/test-reporter):

```yaml theme={"theme":"css-variables"}
      - name: Show the results
        if: always()
        uses: dorny/test-reporter@v1
        with:
          name: Mobster checks
          path: .mobster/ci/junit.xml
          reporter: java-junit
```

Each check is a test case named after the check, grouped by device. A flaky check passes with the property `flaky=true` unless you run with `--strict`. A quarantined check shows as skipped.

## Every check, not only the changed screens

To run every check, on a schedule or on `main`, call `mobster test` in a job of its own:

```yaml .github/workflows/nightly.yml theme={"theme":"css-variables"}
name: nightly checks
on:
  schedule:
    - cron: "0 3 * * *"
jobs:
  checks:
    runs-on: [self-hosted, macOS, mobster]
    timeout-minutes: 90
    steps:
      - uses: actions/checkout@v4
      - id: replay
        uses: actions/cache/restore@v4
        with:
          path: .mobster/cache/replay
          key: mobster-replay-${{ github.run_id }}-${{ github.run_attempt }}
          restore-keys: |
            mobster-replay-
      - run: |
          /Applications/Mobster.app/Contents/MacOS/mobster-agent sim doctor --fix
          /Applications/Mobster.app/Contents/MacOS/mobster-agent test --video --junit build/junit.xml --html build/mobster-report
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
      - if: always()
        uses: actions/cache/save@v4
        with:
          path: .mobster/cache/replay
          key: ${{ steps.replay.outputs.cache-primary-key }}
      - if: always()
        uses: actions/upload-artifact@v4
        with:
          name: mobster-nightly
          path: build/mobster-report
```

* Each pull request's first run of [the workflow](#the-workflow) restores the steps this job recorded, and replays each check that passed here on any new build, on the same iOS major version and simulator.
* On a public repository, a pull request from a fork can restore these steps. They hold the labels your checks tapped and the text of the screens they acted on. If those screens show anything private, leave the two cache steps out of this job.
* Point each check's `app.path` at your build, such as `.mobster/build/Build/Products/Debug-iphonesimulator/<App>.app`, and build it in a step before the checks.
* `--parallel N` runs N simulators at once. Keep N at or below half the runner's cores. On a Mac with 8 GB of memory, keep it at 2.

## Several machines

`--shard I/N` splits the checks evenly: run `mobster test --shard 1/3`, `--shard 2/3` and `--shard 3/3` on three runners with a matrix strategy, and upload each runner's folder. An empty shard exits 0.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.