Skip to main content

Mobile development · Intermediate · 18 min

Write end-to-end mobile tests with Maestro

By Padding · Updated 18 Nov 2026
macOS or Linux · Maestro CLI 2.12.1 · Java 17 or later · Android emulator or iOS simulator

You will have a small Maestro suite for a mobile app, with stable test IDs in React Native or Flutter, a shared sign-in flow fed by environment variables, smoke and full runs split by tags, and a CI job that runs the smoke flows on an Android emulator.

On this page

Unit and component tests prove that pieces of your app behave. They do not prove that the installed app opens, that sign-in reaches the home screen, or that the button a customer needs is not hidden behind the keyboard. An end-to-end test does: it installs the built app on an emulator or simulator and uses it the way a person does.

Maestro writes those tests as short YAML files called flows. Each line is one action, such as "tap Sign in" or "check that Orders is on screen". Three things make it a good first end-to-end tool:

  • It waits for you. Assertions such as assertVisible keep checking the screen until the element appears or a timeout passes, so you do not scatter sleep calls through your tests. Most flakiness in mobile tests comes from fixed waits that are too short on a slow device; Maestro removes most of them.
  • It sits outside the app. Maestro drives the finished binary through the platform's accessibility layer. You add no test library to the app, and the same approach works for React Native, Flutter and native apps.
  • It is quick to iterate. You run one YAML file, see which line failed, edit it and run it again, with no compile step for the test.

Compare that with the two older options. Detox is a grey-box framework for React Native: it runs inside the app's process and knows when the JavaScript thread is idle, which makes it precise but tied to React Native and a native build setup. Appium speaks the WebDriver protocol through drivers for each platform and works with any language, at the cost of more setup and more code per test. Pick Maestro when you want readable flows that a whole team can maintain; reach for Detox or Appium when you need deep app internals or an existing WebDriver estate.

The examples use an orders app with the package name com.example.orders: a sign-in screen, a long list of orders, and an order detail screen. Replace the package name, IDs and text with your own app's as you go.

Step 1 · Install Maestro and connect a device

Maestro needs Java 17 or later. Check what you have:

Bash
java -version

Install the Maestro CLI, pinned to the version this tutorial was written for, so your flows and your CI runner use the same release:

Bash
export MAESTRO_VERSION=2.12.1; curl -fsSL "https://get.maestro.mobile.dev" | bash

The script installs into ~/.maestro/bin. Add that folder to your PATH in ~/.zshrc or ~/.bashrc, open a new terminal, and check the version:

Bash
export PATH="$PATH:$HOME/.maestro/bin"
maestro --version

Maestro is not managed by a package manager here, so it does not update itself. To upgrade later, run the install line again with a newer MAESTRO_VERSION, and change the version in your CI job at the same time.

Start an Android emulator from the Device Manager in Android Studio (or open an iOS simulator from Xcode on a Mac), then install your app on it. For an Expo app this must be a development or release build: Maestro cannot launch your own package name inside Expo Go. Get the Larkfield app ready for release shows npx expo run:android --variant release for that.

Many people in Nigeria and across Africa use low-end Android phones with 2 to 3 GB of memory. Create a second, smaller emulator profile in Device Manager with less RAM and an older Android version you support, and keep it for the smoke run in Step 6. A flow that passes on a fast emulator and fails there is telling you something about your app, not about Maestro.

Check it worked

maestro --version prints 2.12.1. adb devices lists your emulator with the state device, and your app's icon is on the emulator's home screen.

Step 2 · Give the screens stable test IDs

Maestro can find elements by the text a person sees or by an ID. Text is fine for a quick check, but it breaks as soon as someone rewords a button or the app runs in French, Hausa or Swahili. Give every element a flow touches an ID that never changes.

In React Native, use the testID prop. Maestro reads it as the element's id:

TSX
<TextInput testID="sign-in-email" autoComplete="email" keyboardType="email-address" />
<TextInput testID="sign-in-password" secureTextEntry />
<Pressable testID="sign-in-submit" accessibilityRole="button" onPress={signIn}>
  <Text>Sign in</Text>
</Pressable>
<FlatList testID="orders-list" data={orders} renderItem={renderOrder} />

For each order row, build the ID from the record, such as `testID={order-row-${order.number}`}``, so a flow can pick one specific row.

In Flutter, wrap the widget in Semantics with an identifier, which needs Flutter 3.19 or later. A widget Key does not work: Maestro sits outside the Flutter runtime and cannot see keys.

Dart
Semantics(
  identifier: 'sign-in-email',
  child: TextField(
    keyboardType: TextInputType.emailAddress,
    decoration: const InputDecoration(labelText: 'Email'),
  ),
),
Semantics(
  identifier: 'sign-in-submit',
  child: FilledButton(onPressed: _signIn, child: const Text('Sign in')),
),

Use one naming pattern for the whole app, screen-element in kebab case here, and keep it in one place in your design notes so designers and testers use the same names. Rebuild and reinstall the app after adding the IDs.

Check it worked

Search your source for each ID you plan to use (sign-in-email, sign-in-password, sign-in-submit, orders-list) and find exactly one match per ID, except row IDs, which appear once in the row component. The app still looks and behaves the same on the emulator, because IDs are invisible.

Step 3 · Write a first flow that signs in

Create a .maestro folder in the root of your app's repository. Maestro treats it as your workspace. Add .maestro/sign-in-and-see-orders.yaml:

YAML
appId: com.example.orders
---
- launchApp:
    clearState: true
- assertVisible: "Sign in"
- tapOn:
    id: "sign-in-email"
- inputText: "tester@example.com"
- tapOn:
    id: "sign-in-password"
- inputText: "replace-me"
- hideKeyboard
- tapOn:
    id: "sign-in-submit"
- assertVisible:
    id: "orders-list"

Read it top to bottom. The block above --- is the flow's configuration; appId is your package name or bundle ID. launchApp with clearState: true wipes the app's stored data first, so every run starts as a new install with no saved session. On iOS, add clearKeychain: true as well if your app keeps tokens in the Keychain. assertVisible: "Sign in" uses text; the taps use IDs.

The email and password are placeholders. Step 4 moves them out of the file, so do not put a real password here even for a minute; files like this end up in Git.

Run it with the emulator open:

Bash
maestro test .maestro/sign-in-and-see-orders.yaml

Text and ID selectors are regular expressions. "Sign in" also matches "Sign in with phone", so if your screen has both, make the text exact with "^Sign in$" or use the ID.

Check it worked

You can watch the emulator clear the app, launch it, type into both fields and reach the orders list. The terminal lists each command with a tick and ends with the flow passing. If you change orders-list to a wrong ID and run it again, Maestro waits, then fails on that line and names the element it could not find. Put the right ID back afterwards.

Step 4 · Share the sign-in steps and keep the account out of the file

Almost every flow needs to sign in first. Copying those eight lines into each file means fixing eight files when the sign-in screen changes. Move them into a subflow and call it with runFlow.

Create .maestro/subflows/sign-in.yaml:

YAML
appId: com.example.orders
---
- tapOn:
    id: "sign-in-email"
- inputText: ${MAESTRO_TEST_EMAIL}
- tapOn:
    id: "sign-in-password"
- inputText: ${MAESTRO_TEST_PASSWORD}
- hideKeyboard
- tapOn:
    id: "sign-in-submit"
- assertVisible:
    id: "orders-list"

Maestro reads any shell variable whose name starts with MAESTRO_ and makes it available to flows, so the account details come from your environment, not from the repository. Replace the first flow's sign-in lines with one call:

YAML
appId: com.example.orders
---
- launchApp:
    clearState: true
- runFlow: subflows/sign-in.yaml
- assertVisible: "Orders"

Set the variables in your terminal before running. read -s asks for the password without echoing it or saving it in your shell history:

Bash
export MAESTRO_TEST_EMAIL="tester@example.com"
read -s -p "Test password: " MAESTRO_TEST_PASSWORD; echo; export MAESTRO_TEST_PASSWORD
maestro test .maestro/sign-in-and-see-orders.yaml

For values that are not secret, such as which environment to test against, you can pass -e NAME=value to maestro test instead, or set a default in a flow's env header. Give a variable a fallback inside the flow with ${API_REGION || "eu"}. A constant set in a subflow's own env wins over one with the same name from the flow that called it.

Use a dedicated test account on a staging backend, never a real customer's account, and never production. The flow signs in, scrolls and opens records; on production that is a real user doing real things.

Check it worked

grep -r "replace-me" .maestro finds nothing, and grep -rn "MAESTRO_TEST" .maestro shows the two variables only in subflows/sign-in.yaml. The flow still passes. Run it in a new terminal where you have not exported the variables: it fails at the sign-in step, which proves the account now comes from the environment.

Step 5 · Reach items further down a long list

On a real phone the order a tester wants is rarely on the first screen. tapOn only finds elements that are on screen, so scroll to the element first with scrollUntilVisible. Add .maestro/open-an-older-order.yaml:

YAML
appId: com.example.orders
---
- launchApp:
    clearState: true
- runFlow: subflows/sign-in.yaml
- scrollUntilVisible:
    element:
      id: "order-row-1042"
    direction: DOWN
    timeout: 30000
- tapOn:
    id: "order-row-1042"
- assertVisible:
    id: "order-detail-status"
- assertVisible: "Order 1042"

scrollUntilVisible scrolls down by default and gives up after 20 seconds; the flow above allows 30 for a slower emulator. It stops when the element is fully on screen. The order number must exist in your test account's data, which is why the prerequisites ask for seeded records: an end-to-end test is only as stable as the data under it. Reset or reseed that account before each CI run if other tests change it.

If a screen loads from the network, Maestro's assertions already wait for it. When something takes longer than usual, such as a payment confirmation, use extendedWaitUntil with a visible selector and a timeout in milliseconds instead of a fixed pause; the flow moves on as soon as the element appears.

Check it worked

Run maestro test .maestro/open-an-older-order.yaml. On the emulator you see the list scroll until row 1042 appears, then the detail screen opens, and the terminal reports a pass. Change the order number to one that does not exist and the run fails at scrollUntilVisible after the timeout, naming order-row-....

Step 6 · Split smoke and full runs with tags

Some flows must pass before anyone merges code; others can run nightly. Mark them with tags in each flow's configuration block. Add a tag block to sign-in-and-see-orders.yaml:

YAML
appId: com.example.orders
tags:
  - smoke
---

Add tags: with - full to open-an-older-order.yaml in the same way. Then add .maestro/config.yaml to say which files count as flows:

YAML
flows:
  - "*"

When you point Maestro at a folder, it runs only the flow files at that folder's top level and ignores subfolders. That is what keeps subflows/sign-in.yaml from running on its own as if it were a test. The "*" pattern says the same thing explicitly, so nobody later adds "**" without seeing why it is not there.

Run the smoke set, then everything:

Bash
maestro test --include-tags=smoke .maestro
maestro test .maestro

--exclude-tags does the opposite, which is useful for a wip tag on a flow that is not ready.

Your folder now looks like this:

Text
.maestro/
  config.yaml
  sign-in-and-see-orders.yaml   (smoke)
  open-an-older-order.yaml      (full)
  subflows/
    sign-in.yaml

Run the smoke set once on the small, low-memory emulator profile from Step 1, and once with the emulator's language set to another language your app supports. Flows that rely on IDs keep passing; any that fail in the second language have a text selector you should turn into an ID.

Check it worked

The smoke command runs one flow and the full command runs two. Neither output lists subflows/sign-in.yaml as a flow of its own; it only appears inside the flows that call it.

Step 7 · Run the smoke flows in CI on an emulator

A flow you only run on your laptop stops being trusted within a month. Run the smoke set on every pull request. On GitHub Actions, Linux runners can start an Android emulator with hardware acceleration once KVM is enabled. This workflow builds a release APK for an Expo app, starts an emulator, installs the app and runs the smoke flows. Save it as .github/workflows/maestro-smoke.yml:

YAML
name: Maestro smoke tests
on:
  pull_request:

jobs:
  smoke:
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-java@v6
        with:
          distribution: temurin
          java-version: '17'

      - name: Build the release APK
        run: |
          npm ci
          npx expo prebuild --platform android
          cd android && ./gradlew assembleRelease

      - name: Install Maestro
        run: |
          export MAESTRO_VERSION=2.12.1
          curl -fsSL "https://get.maestro.mobile.dev" | bash
          echo "$HOME/.maestro/bin" >> "$GITHUB_PATH"

      - name: Enable KVM
        run: |
          echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
          sudo udevadm control --reload-rules
          sudo udevadm trigger --name-match=kvm

      - name: Run smoke flows on an emulator
        uses: reactivecircus/android-emulator-runner@v2
        env:
          MAESTRO_TEST_EMAIL: ${{ secrets.MAESTRO_TEST_EMAIL }}
          MAESTRO_TEST_PASSWORD: ${{ secrets.MAESTRO_TEST_PASSWORD }}
        with:
          api-level: 34
          arch: x86_64
          target: google_apis
          script: adb install -r android/app/build/outputs/apk/release/app-release.apk && maestro test --include-tags=smoke --format JUNIT --output maestro-report.xml --test-output-dir maestro-output .maestro

      - name: Keep the report and screenshots
        if: always()
        uses: actions/upload-artifact@v7
        with:
          name: maestro-results
          path: |
            maestro-report.xml
            maestro-output/

For a Flutter app, replace the build step with flutter build apk and the APK path with build/app/outputs/flutter-apk/app-release.apk. The script stays on one line on purpose: the install and the test must run in the same shell, after the emulator has booted. Add the two secrets under the repository's Settings, Secrets and variables, Actions; never write them into the workflow file.

If you would rather not run emulators yourself, or need iOS in CI without a macOS runner, Maestro Cloud runs the same flows on hosted devices. Upload an ARM APK or an iOS simulator .app with maestro cloud --app-file <file> --flows .maestro, with the API key in the MAESTRO_CLOUD_API_KEY environment variable, or use the mobile-dev-inc/action-maestro-cloud@v3 action with its api-key, project-id, app-file and include-tags inputs. Check the current plan limits and prices on Maestro's own site before choosing it, because it is a paid service.

Check it worked

Open a pull request. The checks list shows "Maestro smoke tests", and the job log shows the emulator booting, the APK installing and the smoke flow passing. Download the maestro-results artifact from the run page: it holds maestro-report.xml, a JUnit file listing one test case per flow. Break an ID on a branch and the check turns red, and the artifact's screenshots show the screen Maestro was looking at when it gave up.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.