Introduction
Tired of flaky, slow, and complex mobile UI tests? Say hello to Maestro, the open-source, flow-based UI testing framework that promises painless and reliable automation for both iOS and Android.
Maestro uses a simple, human-readable YAML syntax, moving away from complex programming languages and brittle wait commands. This guide will walk you through setting up a foundational test flow using the popular Wiki demo app, exploring advanced concepts like Selectors, Flow Re-usability, and CI/CD integration.
Your First Maestro Flow (The Wiki App Demo)
Our goal is to create a simple test flow that verifies the search functionality of the Wikipedia application.
Prerequisites
Install WSL 2
With recent Windows 11, Microsoft has made it pretty easy to install Windows Subsystem for Linux, aka WSL.
In order to install WSL, open PowerShell as administrator and run the following command:
wsl --install
After running the above command, follow through instructions and restart the computer.
Install Windows Terminal application for refreshing terminal experience.
Set your Linux username and password (Something that you will not forget).
Run the following two commands to update your Ubuntu system. Enter password when prompted.
sudo apt update
sudo apt upgrade
Install Java
After restarting the system, open the Terminal application and click on the dropdown to select Ubuntu. Install Java 17 or higher with the following command:
sudo apt install openjdk-17-jdk
Alternatively, you can install a newer version like Java 21:
sudo apt install openjdk-21-jdk
Install Maestro
Installing Maestro is now just a matter of running following one command.
curl -Ls "https://get.maestro.mobile.dev" | bash
Tada! 🎉
You have successfully installed Maestro on your Windows machine 🙌
Check your Maestro version using the following command:
maestro --version
App Setup:
Ensure the Wikipedia app (e.g., appId: org.wikipedia.beta) is installed on a running Android Emulator or iOS Simulator.
Use the download-samples command to download the samples:
maestro download-samples
This will download the build-in sample Flows and app into a samples/ folder in your current directory.
The Test Flow:
This YAML file defines the actions a user would take: wiki_search_test.yaml
appId: org.wikimedia.wikipedia
---
# Flow: Verify Basic Search Functionality
- launchApp
- tapOn: "Search Wikipedia" # Tap the search bar
- inputText: "Maestro" # Input the search term
- tapOn: "Maestro" # Tap the first search result
# The Assertion: Crucial step for verification
- assertVisible: "Maestro" # Assert that the article title is visible
Running the Test
Execute the flow from your terminal:
maestro test wiki_search_test.yaml
If successful, Maestro confirms the flow passed. If it fails, Maestro provides clear feedback on the failed step.
Advanced Testing with Flow Re-usability (runFlow)
In large projects, redundant steps like logging in should be centralized. Maestro’s runFlow command allows you to modularize and reuse these common sequences.
Scenario: Login and Logout Reusability
We break the logic into two files, enhancing maintainability.
The Reusable Flow: flows/login_flow.yaml
---
# A sub-flow for login. Note: No appId required here.
- tapOn: "Log In"
- inputText: "testuser@example.com"
- tapOn: "Continue"
- inputText: "secretpassword"
- tapOn: "Log In"
- assertVisible: "Welcome Back, Test User"
The Main Test: test/main_test_suite.yaml
appId: org.wikipedia.beta
---
# 1. Setup
- launchApp:
clearState: true
# 2. CALL the reusable Login Flow
- runFlow: flows/login_flow.yaml
# 3. Core Test Logic
- tapOn: "Saved"
- assertVisible: "No Saved Articles"
# 4. A reusable Logout flow could be called here as well.
Mastering Selectors for Flakiness Tolerance
Maestro’s robust selector engine is key to its stability. It allows you to find elements based on various attributes, automatically handling dynamic changes better than traditional frameworks.
| Selector Type | Description | YAML Syntax Example | Stability Priority |
| ID | Based on the element’s resource or accessibility ID. | tapOn: id: "login_button" | Highest. The most reliable for critical elements. |
| Content Description | Based on the element’s accessibility label. | tapOn: description: "Saved Icon" | High. Excellent for icons without visible text. |
| Text | Based on the visible text. Case-insensitive by default. | tapOn: "Log In" | High. Great for buttons and labels. |
| Type | Based on the element type (e.g., TextField, Button). | tapOn: type: "TextField" | Medium. Useful for general interaction but less specific. |
| Traits | Advanced selectors based on state (e.g., checked, selected). | assertVisible: selected: true | High. Ideal for verifying radio buttons or tabs. |
Tip: Use Maestro Studio (maestro studio in the terminal) to visually inspect the running app and instantly get the best selector for any element.
Seamless CI/CD Integration
Integrating Maestro into your Continuous Integration/Continuous Deployment (CI/CD) pipeline ensures tests run automatically on every code change, catching bugs early. Because Maestro is a single, self-contained binary, integration is remarkably simple.
Integration Steps (Example: GitHub Actions)
The process involves setting up the environment (Android SDK/Emulator or iOS Simulator) and then executing the Maestro binary.
- Setup Environment: Use existing CI actions to set up and boot an Android Emulator or iOS Simulator (often on a macOS runner).
- Install Maestro: Download and install the binary on the runner machine.
- Execute: Run the
maestro testcommand, pointing it to your flow files.
# Simplified GitHub Actions Step
- name: Run Maestro Tests
run: $HOME/.maestro/maestro test tests/
Conclusion
Maestro delivers on its promise of “painless mobile test automation.” By adopting its simple YAML syntax, leveraging powerful selectors for stability, and embracing flow modularity with runFlow, your team can build a mobile UI testing suite that is fast, reliable, and genuinely easy to maintain.
Start testing with confidence today!