惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
I
InfoQ
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Announcements
Recent Announcements
GbyAI
GbyAI
爱范儿
爱范儿
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
美团技术团队
罗磊的独立博客
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
雷峰网
雷峰网
M
MIT News - Artificial intelligence
D
Docker
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
博客园 - 叶小钗

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
E2E Testing React Native with Maestro: A Practical Guide
PEAKIQ · 2026-05-06 · via DEV Community

Originally published on PEAKIQ

Source: https://www.peakiq.in/blog/e2e-testing-your-react-native-app-with-maestro



E2E Testing Your React Native App with Maestro

Writing end-to-end tests for mobile apps has always been painful. Appium needs drivers. Detox needs native build hooks. Everything breaks when your UI shifts by 4 pixels. Maestro changes that. It talks to your app the same way a user does — through the accessibility layer — and writes tests in plain YAML.

This guide covers everything: installation, writing your first flow, handling iOS quirks, and plugging Maestro into your CI pipeline.


Why Maestro?

Before we dive in, here's why Maestro stands out against the traditional tools.

Feature Maestro Detox Appium
Setup complexity Minimal High Very High
Language YAML JS/TS JS/Python/Java
Platform support iOS + Android iOS + Android iOS + Android
Zero app changes
Flakiness handling Built-in auto-wait Manual sleeps Manual sleeps
Expo support ✅ First-class Limited Limited

Info: Maestro operates entirely at the accessibility layer. It doesn't touch your JavaScript source, doesn't need npm packages inside your app, and tests the final compiled binary — just like a real user would use it.


Prerequisites

  • Node.js ≥ 18
  • React Native CLI or Expo project
  • For iOS: Xcode + Simulator running
  • For Android: Android Studio + AVD Manager with an emulator running

Installation

Step 1 — Install Maestro CLI

curl -Ls "https://get.maestro.mobile.dev" | bash

Enter fullscreen mode Exit fullscreen mode

Maestro is compatible with macOS, Windows, and Linux. Verify the install:

maestro --version

Enter fullscreen mode Exit fullscreen mode

Step 2 — Start your simulator/emulator

iOS (macOS only):

open -a Simulator

Enter fullscreen mode Exit fullscreen mode

Android:

emulator -avd Pixel_6_API_33

Enter fullscreen mode Exit fullscreen mode

Step 3 — Install and launch your app

# React Native CLI
npx react-native run-ios
npx react-native run-android

# Expo
npx expo start --ios
npx expo start --android

Enter fullscreen mode Exit fullscreen mode


Your First Flow

Create a .maestro/ folder at the root of your project. This is where all your test flows live.

your-app/
├── .maestro/
│   ├── sign-in-flow.yaml
│   └── onboarding-flow.yaml
├── src/
└── package.json

Enter fullscreen mode Exit fullscreen mode

Here's a minimal flow that launches your app and taps a button:

# .maestro/sign-in-flow.yaml
appId: com.yourapp.bundle
---
- launchApp
- tapOn: "Sign In"
- inputText:
    text: "hello@example.com"
    label: "Email"
- inputText:
    text: "supersecret"
    label: "Password"
- tapOn: "Continue"
- assertVisible: "Welcome back"

Enter fullscreen mode Exit fullscreen mode

Run it:

maestro test .maestro/sign-in-flow.yaml

Enter fullscreen mode Exit fullscreen mode

That's it. No compilation step, no linking, no driver setup.


Targeting Components

Maestro gives you two clean ways to target elements in your React Native app.

By visible text

If your component renders visible text, Maestro can find it directly:

- tapOn: "Add to Cart"
- assertVisible: "Item added"

Enter fullscreen mode Exit fullscreen mode

By testID

For components without unique visible text (icons, image buttons), add a testID:

<TouchableOpacity testID="submit-button" onPress={handleSubmit}>
  <Icon name="arrow-right" />
</TouchableOpacity>

Enter fullscreen mode Exit fullscreen mode

Then in your flow:

- tapOn:
    id: "submit-button"

Enter fullscreen mode Exit fullscreen mode

Tip: Prefer testID over text matching for interactive elements. It decouples your tests from copy changes and internationalization.


Handling Text Input

Text input requires two steps: focus the field, then type.

Your React Native component:

<TextInput
  testID="email-input"
  placeholder="Enter your email"
  onChangeText={setEmail}
  keyboardType="email-address"
/>

Enter fullscreen mode Exit fullscreen mode

Your Maestro flow:

- tapOn:
    id: "email-input"
- inputText: "hello@maestro.dev"
- hideKeyboard

Enter fullscreen mode Exit fullscreen mode


Assertions

Maestro ships with a concise set of assertions out of the box.

# Assert an element is visible
- assertVisible: "Dashboard"

# Assert by testID
- assertVisible:
    id: "user-avatar"

# Assert something is NOT on screen
- assertNotVisible: "Loading..."

# Assert text content
- assertVisible:
    text: "You have 3 notifications"

Enter fullscreen mode Exit fullscreen mode


Handling iOS Nested Accessibility (Common Gotcha)

On iOS, React Native sometimes "swallows" touch events when components are deeply nested. You'll hit this when trying to tap something inside a Pressable or TouchableOpacity that's inside another tappable container.

The fix — in your React Native component:

// ❌ Before — inner Text is unreachable
<TouchableOpacity onPress={handlePress}>
  <View>
    <Text>Tap me</Text>
  </View>
</TouchableOpacity>

// ✅ After — disable accessibility on outer, enable on inner
<TouchableOpacity accessible={false} onPress={handlePress}>
  <View>
    <Text accessible={true} testID="tap-target">Tap me</Text>
  </View>
</TouchableOpacity>

Enter fullscreen mode Exit fullscreen mode

Your flow stays clean:

- tapOn:
    id: "tap-target"

Enter fullscreen mode Exit fullscreen mode


Advanced: Parameterized Flows

Avoid duplicating flows for different test scenarios. Use Maestro's parameter support:

# .maestro/sign-in-flow.yaml
appId: com.yourapp.bundle
---
- launchApp
- tapOn: "Email"
- inputText: ${EMAIL}
- tapOn: "Password"
- inputText: ${PASSWORD}
- tapOn: "Sign In"
- assertVisible: "Dashboard"

Enter fullscreen mode Exit fullscreen mode

Run with parameters:

maestro test .maestro/sign-in-flow.yaml \
  -e EMAIL=test@example.com \
  -e PASSWORD=mypassword

Enter fullscreen mode Exit fullscreen mode

This is especially powerful for testing multiple user roles or locales without duplicating flow files.


Running a Full Test Suite

Run every flow in your .maestro/ directory with a single command:

maestro test .maestro/

Enter fullscreen mode Exit fullscreen mode

Maestro will execute all .yaml files sequentially and report results for each one.


Integrating with CI/CD

GitHub Actions

# .github/workflows/e2e.yml
name: E2E Tests

on:
  push:
    branches: [main]
  pull_request:

jobs:
  e2e-android:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: "temurin"
          java-version: "17"

      - name: Install Maestro
        run: curl -Ls "https://get.maestro.mobile.dev" | bash

      - name: Build APK
        run: cd android && ./gradlew assembleDebug

      - name: Start emulator
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: 33
          script: |
            adb install android/app/build/outputs/apk/debug/app-debug.apk
            maestro test .maestro/

Enter fullscreen mode Exit fullscreen mode

Maestro Cloud (Optional)

For parallel execution across real devices, push to Maestro Cloud:

maestro cloud \
  --apiKey $MAESTRO_API_KEY \
  android/app/build/outputs/apk/debug/app-debug.apk \
  .maestro/

Enter fullscreen mode Exit fullscreen mode

This gives you a visual dashboard of historical runs, device logs, and screenshots on failure.


Sample App: Complete Example

Here's a minimal React Native screen and its corresponding Maestro flow.

App.tsx:

import React, { useState } from "react";
import { SafeAreaView, Button, Text, TextInput, StyleSheet } from "react-native";

export default function App() {
  const [taps, setTaps] = useState(0);
  const [text, setText] = useState("");

  return (
    <SafeAreaView style={styles.container}>
      <Button title="Add one" onPress={() => setTaps(taps + 1)} />
      <Button
        title="Add ten"
        testID="add_ten"
        onPress={() => setTaps(taps + 10)}
      />
      <Text>Number of taps: {taps}</Text>
      <TextInput
        testID="text_input"
        placeholder="Change me!"
        onChangeText={setText}
        style={styles.input}
      />
      <Text>You typed: {text}</Text>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, alignItems: "center", justifyContent: "center" },
  input: { borderWidth: 1, width: 200, padding: 8, marginTop: 12 },
});

Enter fullscreen mode Exit fullscreen mode

.maestro/counter-flow.yaml:

appId: com.myapp
---
- launchApp
- tapOn: "Add one"
- tapOn:
    id: "add_ten"
- assertVisible: "Number of taps: 11"
- tapOn: "Change me!"
- inputText: "Hello, Maestro!"
- assertVisible: "You typed: Hello, Maestro!"

Enter fullscreen mode Exit fullscreen mode


Tips for Reliable Tests

  1. Always use testID for anything interactive. Text changes. testID doesn't (unless you change it deliberately).
  2. Don't use sleep. Maestro automatically waits for elements to appear. Explicit sleeps are a code smell — if you think you need one, something else is wrong.
  3. Keep flows small and composable. One flow = one user journey. A sign-in flow shouldn't also test the profile page.
  4. Reset app state between runs. Use clearState: true in launchApp to ensure a clean slate:
- launchApp:
    clearState: true

Enter fullscreen mode Exit fullscreen mode

  1. Use runFlow for shared setup:
# .maestro/helpers/login.yaml
---
- tapOn: "Email"
- inputText: ${EMAIL}
- tapOn: "Sign In"

Enter fullscreen mode Exit fullscreen mode

# Your main flow
---
- launchApp
- runFlow: helpers/login.yaml
- assertVisible: "Dashboard"

Enter fullscreen mode Exit fullscreen mode


Conclusion

Maestro removes the friction from mobile E2E testing. No native bridges, no custom drivers, no flaky sleeps — just YAML that reads like a QA script and runs like a charm.

With full support for both Expo and React Native CLI, built-in handling of timing and async UI, and a one-line CI setup, there's very little reason not to add Maestro to your project today.

Get started:

curl -Ls "https://get.maestro.mobile.dev" | bash
maestro test .maestro/your-first-flow.yaml

Enter fullscreen mode Exit fullscreen mode

Happy testing.


Resources