LogoLogo
πŸš€ Run Maestro tests in the cloud β†’
  • Home
  • Star us on GitHub
  • Getting Started
    • What is Maestro?
    • Installing Maestro
      • macOS
      • Windows
      • Linux
    • Build and Install your App
      • Android
      • iOS
    • Run a Sample Flow
    • Writing Your First Flow
    • Maestro Studio
    • Running Flows on CI
  • Cloud
    • Run Maestro tests in the cloud
    • Cloud Quickstart
    • CI Integration
      • GitHub Actions
        • Maestro GitHub Action for Android
        • Maestro GitHub Action for iOS
        • Maestro GitHub Action for Flutter
      • Bitrise
      • Bitbucket Pipelines
      • CircleCI
      • Integration with any CI platform
    • Pull Request Integration
    • Cloud Reference
      • Build your app for the cloud
      • Configuring OS Version
      • Configuring device locale
      • Device timezones
      • Email Notifications
      • Slack Notifications
      • Webhook Integration
      • Managing Secrets
      • Limits
      • Reusing App Binary
      • IP Allowlist
      • System Status
  • Platform Support
    • Supported Platforms
    • Android - Views
    • Android - Jetpack Compose
    • iOS - UIKit
    • iOS - SwiftUI
    • React Native
    • Flutter
    • Web Views
    • Web (Desktop Browser)
  • Examples
    • Android contacts flow automation
    • Facebook signup flow automation
    • Advanced: Wikipedia Android
    • Page Object Model
  • CLI
    • Cloud
    • Test Suites & Reports
    • Tags
    • Record Your Flow
    • Continuous Mode
    • View Hierarchy
    • Start Device
  • API Reference
    • Commands
      • addMedia
      • assertVisible
      • assertNotVisible
      • assertTrue
      • assertWithAI
      • assertNoDefectsWithAi
      • back
      • clearKeychain
      • clearState
      • copyTextFrom
      • evalScript
      • eraseText
      • extendedWaitUntil
      • extractTextWithAI
      • hideKeyboard
      • inputText
      • killApp
      • launchApp
      • openLink
      • pressKey
      • pasteText
      • repeat
      • retry
      • runFlow
      • runScript
      • scroll
      • scrollUntilVisible
      • setAirplaneMode
      • setLocation
      • startRecording
      • stopApp
      • stopRecording
      • swipe
      • takeScreenshot
      • toggleAirplaneMode
      • tapOn
      • doubleTapOn
      • longPressOn
      • travel
      • waitForAnimationToEnd
    • Common command arguments
    • Selectors
    • Configuration
      • Workspace configuration
      • Flow configuration
      • AI configuration
  • Advanced
    • Nested Flows
    • Wait
    • Loops
    • Conditions
    • Parameters & Constants
    • JavaScript
      • Run JavaScript
      • Outputs
      • Logging
      • Access element text
      • Make HTTP requests
      • GraalJS support
      • JavaScript announcement blog
    • Specify a Device
    • Configure Permissions
    • Detect Maestro in your app
    • Configure Maestro driver timeout
    • onFlowStart / onFlowComplete hooks
    • Test in different locales
    • Structuring your test suite
  • Troubleshooting
    • Known Issues
    • Frequently Asked Questions
    • Bug Report
    • Rollback Maestro
    • Debug Output
    • HOWTOs
      • Arrange your repository for Maestro tests
      • scrollUntilVisible for fragments
  • Community
    • Contributions
    • Articles & Tutorials
    • Case Studies
    • Resources
Powered by GitBook

Read to wire into CI or scale up your testing?

  • Run Maestro tests in the cloud β†’
On this page
  • Interacting with a component by Text
  • Interaction with a component by testID
  • Entering text in a Text Input
  • Create a working sample app with Maestro tests
  • Install Maestro
  • Create a sample app
  • Start the app and test using Maestro
  • Demo
  • Interacting with nested components on iOS
  • Resources

Was this helpful?

Edit on GitHub
  1. Platform Support

React Native

PreviousiOS - SwiftUINextFlutter

Last updated 3 months ago

Was this helpful?

Maestro supports testing React Native screens and apps on both Android and iOS.

Interacting with a component by Text

Maestro can interact with components that display text.

Example: Tap on a Button

For the Button component definition:

<Button
  title="Go"
  onPress={() => Alert.alert('Success!')}
/>

The following command will tap on the Button:

- tapOn: "Go"

Interaction with a component by testID

Maestro can interact with components that have a testID.

Example: Tap on a button with a testID property

For the Button component definition:

<Button
  title="Go"
  testID="continue"
  onPress={() => Alert.alert('Success!')}
/>

The following command will tap on the Button:

- tapOn:
    id: "continue"

Entering text in a Text Input

Example: Enter text into a TextInput.

To input text to a TextInput component, first the component needs to be selected. This can be done using the tapOn command. For the component definition:

<TextInput placeholder="Change me!" />

The following commands will enter "Hello, Maestro!" in the TextInput component:

- tapOn: "Change me!"
- inputText: "Hello, Maestro!"

Create a working sample app with Maestro tests

Install Maestro

Create a sample app

Replace the contents of App.js with:

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>
      <Button
        title="Add one"
        variant="primary"
        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}
      />
      <Text>You typed: {text}</Text>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

Create a test definition file called flow.yaml

Add the following contents:

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

Start the app and test using Maestro

Run npm start in the react native app source directory

Select either Android or iOS Simulator

In another terminal, run maestro test flow.yaml

When the Expo app launches, select the app that you’re testing

Demo

Interacting with nested components on iOS

In some cases, you may run into issues with nested tappable / accessible elements on iOS. You can resolve these issues by enabling accessibility for the inner component and disabling it for the outer container.

Example: Tapping on nested Text Component

<TouchableOpacity 
  style={{ borderWidth: 1, margin: 5, padding: 10, backgroundColor: '#ddd' }} 
   accessible={false}>
  <Text>This is the wrapper button </Text>
  <TouchableOpacity 
    style={{ backgroundColor: 'red', padding: 5, width: '50%', marginTop: 10 }} 
     accessible={true}>
    <Text>I'm a small button</Text>
  </TouchableOpacity>
</TouchableOpacity>

The following command will tap on the nested Text Component:

- tapOn: "I'm a small button"

Resources

Follow the Expo Go Quickstart instructions on

by Alexander Hodes

Maestro install instructions
React Native environment setup
A great introduction to Maestro with React Native
E2E testing of React Native apps using EAS and Maestro (Expo documentation)
28MB
Screen Recording 2023-01-11 at 21.24.32.mov
React Native app tested using Maestro