Efficiently Running Maestro UI Tests in Bitrise for Your Android App
type
Post
status
Published
date
Apr 13, 2023
slug
automate-android-app-ui-testing-maestro-on-bitrise
summary
Learn practical tips for integrating Maestro and Bitrise to streamline UI testing and optimize Android app development for increased efficiency and productivity.
tags
Bitrise
CI/CD
Automate
Maestro
UI Testing
GitHub
category
Android
icon
password
Effortless Android UI Testing with Maestro on Bitrise CI/CD
In this blog, we will walk you through setting up your Android app on Bitrise to automate builds and integrate UI testing using Maestro. Bitrise is a popular CI/CD platform for mobile app development, while Maestro is a powerful UI testing framework.
Prerequisites:
Before diving in, please ensure you have set up your Android app on Bitrise by following the instructions in this guide: Automating and Optimizing Android Jetpack Compose App Builds with Bitrise and GitHub
Step 1: Update bitrise.yml
First, navigate to the Edit Workflow page and click on the bitrise.yml tab.

bitrise.yml
Copy and paste the YAML code provided below into the bitrise.yml editor. This code includes a custom workflow named "Maestro-Test-Android" that automates the build process and integrates Maestro UI testing.
--- format_version: '11' default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git project_type: android workflows: Maestro-Test-Android: description: | Deploys app using [Deploy to bitrise.io Step](https://devcenter.bitrise.io/en/getting-started/getting-started-with-android-apps.html#deploying-an-android-app-to-bitrise-io-53056). Next steps: - Check out [Getting started with Android apps](https://devcenter.bitrise.io/en/getting-started/getting-started-with-android-apps.html) for signing and deployment options. - [Set up code signing with *Android Sign* Step](https://devcenter.bitrise.io/en/code-signing/android-code-signing/android-code-signing-using-the-android-sign-step.html). steps: - activate-ssh-key@4: {} - git-clone@7: {} - cache-pull@2: {} - install-missing-android-tools@3: inputs: - gradlew_path: "$PROJECT_LOCATION/gradlew" - android-build@1: inputs: - project_location: "$PROJECT_LOCATION" - module: "$MODULE" - variant: "$VARIANT" - cache_level: none - script: title: Print project location and APK output directory inputs: - content: | #!/bin/bash echo "Project location: $PROJECT_LOCATION" echo "APK output directory: $PROJECT_LOCATION/$MODULE/build/outputs/apk/$VARIANT/" - avd-manager@1: {} - wait-for-android-emulator@1: {} - script: title: Install Maestro and run e2e tests inputs: - content: |- #!/bin/sh set -ex # Maestro version if [[ -z "$maestro_cli_version" ]]; then echo "If you want to install a specific version of Maestro CLI, please set the environment variable maestro_cli_version to the version you want to install." else echo "Installing Maestro CLI version $maestro_cli_version" export MAESTRO_VERSION=$maestro_cli_version; fi # Install maestro CLI echo "Installing Maestro CLI" curl -Ls "https://get.maestro.mobile.dev" | bash export PATH="$PATH":"$HOME/.maestro/bin" echo "MAESTRO INSTALLED - Check Version" maestro -v $ANDROID_HOME/platform-tools/adb install "$BITRISE_APK_PATH" cd $PROJECT_LOCATION ls pwd echo "Running tests with Maestro" maestro test .maestro/dummy.yaml - sign-apk@1: run_if: '{{getenv "BITRISEIO_ANDROID_KEYSTORE_URL" | ne ""}}' - cache-push@2: {} - deploy-to-bitrise-io@2: {} meta: bitrise.io: stack: linux-docker-android-20.04 machine_type_id: standard app: envs: - opts: is_expand: false PROJECT_LOCATION: "." - opts: is_expand: false MODULE: app - opts: is_expand: false VARIANT: debug - opts: is_expand: false _JAVA_OPTIONS: "-Xms1024m -Xmx2048m" - opts: is_expand: false GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError"
Step 2: Save Changes
Click on the "Save" button to store the updated bitrise.yml configuration.

Step 3: Verify Workflow Configuration
Go to the Workflow tab and ensure that the "Maestro-Test-Android" workflow is listed. In this workflow, you will find a step titled "Install Maestro and run e2e tests." This step contains a script that installs the Maestro CLI and runs the Maestro tests using the specified dummy.yaml file.

Code for Install Maestro and run e2e tests step:
#!/bin/sh set -ex # Maestro version if [[ -z "$maestro_cli_version" ]]; then echo "If you want to install a specific version of Maestro CLI, please set the environment variable maestro_cli_version to the version you want to install." else echo "Installing Maestro CLI version $maestro_cli_version" export MAESTRO_VERSION=$maestro_cli_version; fi # Install maestro CLI echo "Installing Maestro CLI" curl -Ls "https://get.maestro.mobile.dev" | bash export PATH="$PATH":"$HOME/.maestro/bin" echo "MAESTRO INSTALLED - Check Version" maestro -v $ANDROID_HOME/platform-tools/adb install "$BITRISE_APK_PATH" cd $PROJECT_LOCATION ls pwd echo "Running tests with Maestro" maestro test .maestro/dummy.yaml
Update your Triggers
If you have changed your
bitrise.yml
as above steps, please ensure your triggers are updated as well if you have set them prior.Go to the Triggers tab and update:

Step 4: Check for dummy.yaml in Your Project
Before running the workflow, make sure your sample app contains the required dummy.yaml file. This file defines the Flows, which represent user journey segments in your app, such as Login, Checkout, or Add to Cart. Maestro uses these Flows to perform UI testing.
Reference: https://maestro.mobile.dev/

Step 5: Run the Workflow
Click on the "Run Workflow" button and input your branch name to start the Bitrise build. A new browser tab will open, showing the build progress. Click on the "Follow" button to track the build steps without scrolling.


Step 6: Observe the Maestro UI Test
Once the build is successful, navigate to Step 8 in the logs to see the Maestro UI Test running. The Maestro CLI will install, execute the tests, and output the results in the build log.


Conclusion
Congratulations! You have successfully set up your Android app on Bitrise to automate builds and integrate UI testing using Maestro. With this foundation, you can now focus on developing your app's features and rely on Bitrise and Maestro to streamline your build and testing processes.
Note
Maestro has their own cloud offering which is convenient to use as well and extremely simply to set up!
Maestro Cloud: https://cloud.mobile.dev/
Upcoming Blog posts will address all the interesting features of Maestro like screen recordings, test reports and more! Stay tuned!
Reference
Maestro UI Testing Framework: https://maestro.mobile.dev/
Bitrise: https://bitrise.io/