Caracal Starter
Testing

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-maestro

Writing tests

Go to the maestro directory and write your tests. Read more about how to write end-to-end tests with Maestro in the official documentation.

To run the tests, execute the following command:

pnpm e2e-test

This will run the tests on the local emulator.

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 with android-test-github or 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 with android-test-maestro-cloud or 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.

On this page