# Write Maestro End-to-End Tests for a React Native App

Yes. An agent reads your screens and their testIDs, writes Maestro flows under .maestro, adds an emulator job to CI and opens a pull request with the flows.

[Run this on Rush](https://cloud.getrush.ai/run/write-maestro-tests/react-native/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads the app before it writes a flow. In a project like thecodingmachine/react-native-boilerplate, the app lives under `template/`: `package.json` pins `react-native` 0.84.0, `react` 19.2.3, `@react-navigation/native` 7.1.16 with `@react-navigation/stack`, `@tanstack/react-query`, `i18next` with `react-i18next`, `ky`, `zod` and `react-native-mmkv`, and its `test` script is `jest` with the `react-native` preset and `**/*.test.ts?(x)` as the match. The existing tests are component tests: `src/screens/Example/Example.test.tsx` presses `change-language-button` and `change-theme-button` through `@testing-library/react-native`, and `ThemeProvider.test.tsx` and `Skeleton.test.tsx` cover the theme and loader. A search for `maestro` and `detox` across the repository finds nothing, and `.github/workflows/boilerplate-checks.yml` runs only eslint, prettier, `tsc` and jest on pull requests that touch `template/`.

The agent maps what a flow can reach. `src/navigation/Application.tsx` is a stack with two screens, `Paths.Startup` and `Paths.Example`, headers hidden; `Startup.tsx` resolves a query and calls `navigation.reset` to `Example`, so the first visible screen is the example one. `Example.tsx` renders the title from `screen_example.title` in `src/translations/en-EN.json` (`Welcome on The React Native Boilerplate`) and three `TouchableOpacity` buttons with `testID` values `fetch-user-button`, `change-theme-button` and `change-language-button`. The first fetches `users/{id}` through `ky` from `API_URL`, inlined at build time by `babel-plugin-inline-dotenv`, and shows an `Alert` from `screen_example.hello_user`; the second swaps the theme between `default` and `dark` and persists it to MMKV under `theme`; the third toggles the language between `en-EN` and `fr-FR`. `android/app/build.gradle` sets `applicationId "com.boilerplate"`, which is the `appId` every flow needs.

It writes `template/.maestro/` with one flow per behaviour: `startup.yaml` launches the app with `clearState: true` and asserts the English title is visible; `language.yaml` taps `id: change-language-button` and asserts the French title from `fr-FR.json`, then taps again and asserts the English one; `theme.yaml` taps `id: change-theme-button`, takes a screenshot, taps again and takes another, since the theme has no text to assert on; `fetch-user.yaml` taps `id: fetch-user-button` and asserts the `Hi, my name is` prefix of the alert, and is marked as needing a reachable `API_URL` in a comment at the top. Maestro's `id` selector matches the native identifier React Native sets from `testID`, so the flows use the ids the component tests already rely on and add no new ones. A `config.yaml` in the same directory sets the flow order, and `package.json` gains an `e2e` script that runs `maestro test .maestro`.

The sandbox has no Android emulator or iOS simulator, so the agent does not run the flows against a device and the pull request says so. What it checks instead: each flow parses as YAML, every `id` it taps exists as a `testID` in `src/` (a grep it keeps in the record), every asserted string exists in the translation files, and the new CI job is valid under `actionlint`. That job, `template/e2e` in a new `.github/workflows/boilerplate-e2e.yml`, builds the debug APK with `./gradlew assembleDebug`, boots an emulator with `reactivecircus/android-emulator-runner`, installs the Maestro CLI and runs the flows, uploading screenshots as an artifact when a flow fails.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Write Maestro end-to-end tests for this React Native app. Read package.json, the navigation setup, every screen under src/screens and the translation files first, and list the testID values the screens expose. Write one flow per user-visible behaviour under .maestro, using the app's applicationId from android/app/build.gradle as appId, tapping by id where a testID exists and asserting on strings taken from the translation files. Add a config.yaml for the flow order and an e2e script in package.json. Add a GitHub Actions workflow that builds the debug APK, runs the flows on an Android emulator and uploads screenshots on failure. You cannot run a device in your sandbox: check that every id and string you reference exists in the source, validate the workflow with actionlint, and say in the pull request that the flows were not executed. Do not change screens or add testIDs unless a flow cannot be written without one, and list any you add.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch with the `.maestro/` directory (four flows and a `config.yaml`), the `e2e` script in `package.json`, and the new emulator workflow. The description lists each flow with the screen it covers, the ids and strings it references and the source line each one comes from, states that the flows were checked against the source but not executed on a device, and names the one flow (`fetch-user.yaml`) that depends on an `API_URL` the CI job must provide.

The run's record keeps the grep that matched each `testID` and translation key and the `actionlint` output for the workflow, so a reviewer can see the flows reference real elements without opening every screen.

Before merging, a reviewer runs `maestro test .maestro` once on a local emulator or lets the new workflow run on the pull request, checks the emulator API level and the Gradle cache settings in the job, and decides whether the `fetch-user` flow should point at a mock server or be left out of CI.

## Run it on every new screen

In the console, an automation in the Project that has the repository, with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and `branch_patterns` for your default branch, starts one run per pull request, with the pull request as its context. Its prompt asks for a Maestro flow on the pull request's branch when the pull request adds a file under `src/screens`, so the flow lands with the screen rather than weeks later.

From your own server, the same work is one `POST /o/{org}/sessions` with this body and the repository in `resources`, and a webhook on the API key reports `run.completed` with the `session_url` to read the pull request link.

## Why run it on Rush?

End-to-end flows fail for boring reasons: an id that was renamed, a string that is only in one language, an `appId` copied from another project. Writing them means reading the navigation, every screen and the translation files together, which is slow by hand and exactly what an agent with the whole repository in front of it does well. Each id and string in the flows is traced to a source line in the pull request.

The agent is also clear about what it did not do. A sandbox has no emulator, so the flows are checked against the source and the device run is left to the workflow it adds, and the record shows those checks rather than a claimed green run. Several apps, or several screens of one app, can be covered at the same time in separate sandboxes.

## Frequently asked questions

### Does Maestro's id selector find a React Native testID?

Yes. React Native exposes `testID` as the native view identifier on both platforms, and Maestro's `id` selector matches it. The flows reuse the ids the component tests already press, so nothing needs to be added to the screens for these flows.

### Will it add testIDs to my components?

Only when a flow cannot be written otherwise, and the prompt asks it to list each one. In the example app the three buttons already carry ids and the title is text, so no component changes.

### Can it run the flows itself?

Not on a device: the sandbox has no Android emulator or iOS simulator. It validates the YAML, checks every id and string against the source, and writes the emulator job so the first real run happens in CI on the pull request.

### What about iOS?

The same flows run on iOS, with `appId` set to the bundle identifier, which this template derives from the product name. The CI job targets Android because an emulator runs on a Linux runner; an iOS simulator job needs a macOS runner and can be added in a follow-up.

### How does the fetch-user flow get an API?

`API_URL` is inlined at build time, so the CI job must set it before `assembleDebug`. The pull request suggests a small mock server started in the job or leaving that flow out of CI until one exists.

## More React Native jobs

- [Add Biometric Login to a React Native App](https://getrush.ai/run/add-biometric-auth/react-native/)
- [Add Crash Reporting to a React Native App](https://getrush.ai/run/add-crash-reporting/react-native/)
- [Add Deep Links to a React Native App](https://getrush.ai/run/add-deep-links/react-native/)

## More jobs like this: Write the missing tests

- [Validate Kubernetes Manifests in CI](https://getrush.ai/run/write-manifest-tests/kubernetes/)
- [Write Tests That Run Alembic Migrations Up and Down](https://getrush.ai/run/write-migration-tests/alembic/)
- [Write System Tests for a Rails App](https://getrush.ai/run/write-minitest-system-tests/rails/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
