End-to-End Testing
How to write end-to-end tests using Maestro.
Writing end-to-end tests is one of the best ways to ensure that your app is working as expected and simulate exactly how a user would interact with it. However, running those tests can be challenging and time-consuming due to their nature and the need to run them on a device or emulator.
The starter includes Maestro — the easiest way to run end-to-end tests, yet very powerful with many features that make your life easier.
One of Maestro's best features is its user-friendly test writing capability. It's incredibly simple to write tests, making it accessible to PMs, QAs, and even designers.
Watch this talk by Henry Moulton for more details about Maestro and how it can help you write better tests: Henry Moulton – React Native end-to-end testing with Maestro | App.js Conf 2023
Installing Maestro
To install Maestro, run the following:
# A simple npm script that runs: curl -Ls 'https://get.maestro.mobile.dev' | bash
pnpm install-maestroWriting tests
The flows live in .maestro/. Read more about writing them in the official documentation.
| Flow | What it covers |
|---|---|
auth/onboarding.yaml | Fresh install shows onboarding; "I already have an account" opens Sign in |
auth/sign-up.yaml | Create an account, then Profile shows the name and email |
auth/login-with-validation.yaml | Required and format errors, wrong password error, then a successful sign in |
app/tabs.yaml | Home, Profile and Settings (theme switch), then logout |
Shared steps live in .maestro/utils/ (tagged util, so they never run on their own):
launch-app.yaml: clears state, launches the app, reconnects the Expo dev client to Metro and closes the developer menu.create-account.yaml: fills in Create account and waits for the Home tab.logout.yaml: opens Settings, scrolls to Logout and waits for Sign in.login.yaml: signs in withEMAILandPASSWORD.dismiss-password-prompt.yaml: closes an iOS password sheet if one appears.
Accounts are stored on the device, and every flow starts from a cleared state, so each flow creates its own throwaway account. pnpm e2e-test passes the test values:
maestro test .maestro/ -e APP_ID=com.caracal.development -e NAME='E2E User' -e EMAIL=e2e.user@example.com -e PASSWORD=secret1Running tests on iOS
The flows run against the development build:
- Start the app with
pnpm ios --device <simulator UDID>; this also starts Metro on port 8081. - Run
pnpm e2e-test. To target one simulator, add--device <UDID>.
If port 8081 is taken (another project's Metro, for example), start this app on another port and tell the flows about it:
pnpm ios --device <UDID> --port 8082
pnpm e2e-test --device <UDID> -e METRO_URL=http%3A%2F%2Flocalhost%3A8082METRO_URL is the URL-encoded Metro address that utils/launch-app.yaml uses to reconnect the development build after clearState.
Prepare the simulator once before running the suite:
- Keep only an English keyboard (Settings → General → Keyboard → Keyboards). Input methods such as Vietnamese Telex rewrite the typed text.
- Turn off AutoFill Passwords and Passkeys and Suggest Strong Passwords (Settings → General → AutoFill & Passwords). Otherwise iOS shows password sheets that cover the form.
These settings live on the simulator, so clearState does not reset them.
Running tests on CI
Running tests on CI is very important to ensure that your code doesn't break when you push to GitHub. However, running end-to-end tests is quite expensive and time-consuming. To test your app on CI, you need to first build the app, set up the emulator, and then run the tests. This process can consume a significant amount of time and resources.
For this reason, we do not recommend running end-to-end tests on every pull request. Instead, we recommend running them for pull requests that contain specific labels so that you can trigger the tests manually whenever you feel a PR is ready to be tested.
The starter comes with three GitHub Actions workflows for E2E testing:
Currently, only Android is supported for CI-based E2E tests. iOS support is planned.
-
e2e-android.yml— Triggered when a PR is labeled withandroid-test-githubor run manually from the Actions tab. This action generates a staging build for the app, sets up an emulator, and runs the tests using Maestro. -
e2e-android-maestro.yml— Triggered when a PR is labeled withandroid-test-maestro-cloudor run manually from the Actions tab. This action runs the tests using Maestro Cloud. You will need to add your Maestro Cloud token to GitHub secrets. -
e2e-android-eas-build.yml— Accepts an EAS APK URL and runs the tests. This action is triggered manually from the Actions tab.