Automate Android and iOS App Tests in the Cloud

Run Your Appium, Espresso, XCUITest, and Maestro Suites as They Are, in Parallel on 50,000+ Real Devices.

Mobile App Testing

React Native testID Best Practices for Appium Testing

React Native testID becomes the resource-id on Android and the name on iOS. See which Appium locators match it and why Android id lookups fail by default.

Last Updated on:

A React Native button with testID="login-submit-btn" matches an Appium ~login-submit-btn lookup on iOS and misses the same lookup on Android. React Native hands testID and accessibilityLabel to different native attributes on each platform, and Appium's locator strategies read those native attributes, not the React Native props.

Every result below comes from WebdriverIO 10.0.2 scripts run as printed on TestMu AI in October 2026, against a real Pixel 8 on Android 14 and an iPhone 16 simulator on iOS 18.0, both on Appium 3.0.2. The app under test is a React Native 0.81.5 screen running in Expo Go.

That screen is saved as a public Expo Snack, so you can open the same code yourself.

If your Appium React Native setup is not running yet, start with React Native testing on Android and iOS or the Appium tutorial.

Overview

Give every React Native element a unique testID for Appium and keep accessibilityLabel for screen readers. React Native turns testID into the resource-id on Android and into the accessibility identifier, which Appium reads as name, on iOS. Find it with id on Android after setting disableIdLocatorAutocompletion to true, and with accessibility id on iOS.

How Do You Find a React Native testID in Appium?

  • Android (UiAutomator2): Appium's id strategy finds a React Native testID once disableIdLocatorAutocompletion is true. With default settings, UiAutomator2 adds the app package to a bare id and the lookup misses. Works with default settings: No.
  • iOS (XCUITest): Appium's accessibility id and id strategies both find a React Native testID, because XCUITest reports the accessibility identifier as the element's name. Works with default settings: Yes.
  • Android (accessibility id): On Android, Appium's accessibility id strategy matches a React Native accessibilityLabel, not the testID, so a lookup such as ~login-submit-btn misses on Android but matches on iOS.

Which React Native Practices Keep Appium Tests Fast and Accessible?

  • accessibilityLabel: A React Native accessibilityLabel should be a phrase a person understands, never a copy of the testID, because TalkBack and VoiceOver read the label aloud.
  • FlatList: Render long React Native lists with FlatList instead of ScrollView. With a thousand rows on a Pixel 8, each Appium page-source call took about 18 seconds for ScrollView and under one second for FlatList.
  • Real-device runs: TestMu AI App Automation runs the same Appium checks on real Android and iOS devices when isRealMobile is true; without isRealMobile, the session runs on an emulator or simulator.

How React Native Props Map to Appium Locators

React Native maps each prop to a different native attribute. On Android, testID becomes the view's resource-id, and the React Native Android source explains why in a comment: black-box UI testing frameworks cannot read view tags, and exposing testID as the resource-id avoids "polluting the content-description with test identifiers."

On iOS, testID becomes the accessibility identifier, which the XCUITest driver reports as the element's name. accessibilityLabel becomes content-desc on Android and label on iOS, the text TalkBack and VoiceOver announce.

React Native propAndroid attribute (UiAutomator2)iOS attribute (XCUITest)Appium lookup that matches it
testIDresource-idnameAndroid: id with autocompletion off, or UiSelector().resourceId(). iOS: accessibility id or id.
accessibilityLabelcontent-desclabelAndroid: accessibility id. iOS: a predicate on label.
Text childrentextlabel and valueText-based lookups, which break whenever the copy changes.

The test screen gives its login button both props, with different values:

<Pressable
  testID="login-submit-btn"
  accessibilityLabel="Submit login form"
  accessibilityRole="button"
  style={styles.btn}>
  <Text>Log in</Text>
</Pressable>

The authors' May 2025 captures show the same split for an Image component in their Expo app, with testID react-logo and accessibilityLabel React Logo. On Android, Appium Inspector lists react-logo as the image's id and React Logo as its accessibility id.

Appium Inspector on Android showing id react-logo and accessibility id React Logo for a React Native image

On an iOS 18.2 simulator, an Accessibility ID search for react-logo returned one element, and the page source shows its name as react-logo and its label as React Logo.

Appium Inspector on an iOS 18.2 simulator finding one element by Accessibility ID react-logo

Why Can't Appium Find a React Native testID on Android?

The UiAutomator2 driver adds the app package to any id locator that lacks one, so id=login-submit-btn is sent as <package>:id/login-submit-btn, and React Native testIDs never carry that prefix. The UiAutomator2 driver README documents the rewrite and the setting that turns it off, disableIdLocatorAutocompletion.

The files below produced every output in this section. session.mjs opens the device session with appiumVersion set to 3.0.2, the highest version on the supported Appium versions list for real Android devices on TestMu AI.

// session.mjs: opens one TestMu AI device session for Android or iOS
import { remote } from 'webdriverio';

const DEVICES = {
  android: { deviceName: 'Pixel 8', platformVersion: '14',
    isRealMobile: true },
  ios: { deviceName: 'iPhone 16', platformVersion: '18.0',
    isRealMobile: false }, // simulator: Expo Go's iOS build is sim-only
};

export const openSession = (platformName) => remote({
  protocol: 'https', hostname: 'mobile-hub.lambdatest.com', port: 443,
  path: '/wd/hub', logLevel: 'error',
  user: process.env.LT_USERNAME, key: process.env.LT_ACCESS_KEY,
  capabilities: { platformName, 'LT:Options': { ...DEVICES[platformName],
    appiumVersion: '3.0.2', app: process.env.APP_URL, w3c: true,
    build: 'RN testID locators' } },
});

demo.mjs opens the public Snack inside Expo Go through a deep link. With your own APK or IPA, upload the build, pass its app URL in APP_URL, set isRealMobile to true for iOS, and drop the deep link.

// demo.mjs: opens a session and loads this article's Snack in Expo Go
import { openSession } from './session.mjs';

export async function openDemo(platform, url = process.env.SNACK_URL) {
  const driver = await openSession(platform);
  const target = driver.isIOS
    ? { bundleId: 'host.exp.Exponent' }
    : { package: 'host.exp.exponent' };
  await driver.execute('mobile: deepLink',
    { url, ...target });
  const ready = driver.isIOS
    ? '~login-submit-btn'
    : 'android=new UiSelector().resourceId("login-submit-btn")';
  await driver.$(ready).waitForExist({ timeout: 60000 });
  return driver;
}

locators.mjs checks the same button with the id and accessibility id strategies, then switches off id autocompletion on Android and tries the bare id again. The full list of strategies is in locators in Appium.

// locators.mjs: one React Native button, four Appium lookups
import { openDemo } from './demo.mjs';
const driver = await openDemo(process.argv[2] || 'android');
async function check(sel) {
  const found = await driver.$(sel).isExisting();
  console.log(found ? 'found  ' : 'missing', sel);
}
await check('id=login-submit-btn');
await check('~login-submit-btn');
await check('~Submit login form');
if (driver.isAndroid) {
  await driver.updateSettings({ disableIdLocatorAutocompletion: true });
  await check('id=login-submit-btn');
}
await driver.deleteSession();

On the Pixel 8 (UiAutomator2 driver 5.0.1), node locators.mjs android printed:

missing id=login-submit-btn
missing ~login-submit-btn
found   ~Submit login form
found   id=login-submit-btn

On the iPhone 16 simulator (XCUITest driver 9.3.2), node locators.mjs ios printed:

found   id=login-submit-btn
found   ~login-submit-btn
missing ~Submit login form

The accessibility id strategy matched accessibilityLabel on Android and testID on iOS, and the bare id matched on Android only after the setting changed. To apply the setting from the start of every session on TestMu AI, add 'appium:settings[disableIdLocatorAutocompletion]': true inside LT:Options. In a separate Pixel 8 session that placement read true before the first command, while the same capability at the top level did not reach the driver.

Without the setting, these lookups also matched the testID:

  • UiSelector().resourceId() - android=new UiSelector().resourceId("login-submit-btn") matched in every Android run, and it is the lookup demo.mjs waits on. The UiAutomator2 README warns that Google plans to remove UiSelector support from UiAutomator, which would break every -android uiautomator locator.
  • XPath on resource-id - //*[@resource-id="login-submit-btn"] matched as well, but it searches the whole page source and was the slowest lookup in an exploratory Pixel 8 run.

Keep testID and accessibilityLabel Separate

One workaround for the Android mismatch is copying the testID into accessibilityLabel, so one ~checkout-btn lookup passes on both platforms. The test screen's Checkout button does exactly that:

<Pressable
  testID="checkout-btn"
  accessibilityLabel="checkout-btn"
  accessibilityRole="button"
  style={styles.btn}>
  <Text>Checkout</Text>
</Pressable>

Appium then reported content-desc="checkout-btn" on Android and label="checkout-btn" on iOS, the string TalkBack and VoiceOver read to a screen-reader user. Mobile app accessibility covers what those users need from a label instead.

  • testID for test code - one stable, unique string per element, such as login-submit-btn, located with id on Android and accessibility id on iOS.
  • accessibilityLabel for people - a short phrase that describes the action, such as Submit login form. React Native's View reference says the default label joins the element's Text children, so set one explicitly when that default is missing or unclear.
  • Icon-only controls - a button with no Text child gets no default label, so give it a spoken phrase in accessibilityLabel and a separate testID.
  • List rows - derive each row's testID from the item key, as the Row component further down does with 'item-' + item.id, so no two rows share one.
Note

Note: Run these locator checks on real Android and iOS devices with TestMu AI. Try TestMu AI free

How the accessible Prop Changes What Appium Sees

React Native's accessibility guide says accessible turns into focusable on Android and isAccessibilityElement on iOS, so assistive technology can treat the container as a single element. The authors' May 2025 captures on an iOS 18.2 simulator showed what that did to tests: with accessible={true} on a container, Appium Inspector listed it as one element whose name and label merged its children's text, with no child elements shown.

Appium Inspector on iOS showing a container with accessible set to true and its children's text merged into one element

With accessible={false}, each child appeared as its own element again.

Appium Inspector on iOS listing child text elements separately when the container's accessible prop is false

On React Native 0.81.5, children of a grouped container stayed in the tree on both platforms. The test screen has a grouped cart row and an ungrouped one:

<View testID="cart-row-grouped" accessible={true} style={styles.box}>
  <Text testID="grouped-name">Headphones</Text>
  <Text testID="grouped-price">$99</Text>
</View>
<View testID="cart-row-open" style={styles.box}>
  <Text testID="open-name">Phone case</Text>
  <Text testID="open-price">$29</Text>
</View>

tree.mjs reports whether a grouped child, the hidden banner from a later section, and the list rows appear in the page source:

// tree.mjs: grouped, hidden, and list views in the page source
import { openDemo } from './demo.mjs';
const driver = await openDemo(process.argv[2] || 'android');
const key = driver.isIOS ? ' name="' : ' resource-id="';
async function report(label) {
  const xml = await driver.getPageSource();
  const has = (id) => xml.includes(key + id + '"');
  const rows = (xml.match(/(name|resource-id)="item-\d/g) || []).length;
  console.log(label, '| grouped child:', has('grouped-name'),
    '| hidden banner:', has('hero-decoration'), '| rows:', rows);
}
await report('defaults');
if (driver.isAndroid) {
  await driver.updateSettings({ ignoreUnimportantViews: true });
  await report('ignoreUnimportant');
}
await driver.deleteSession();

On the Pixel 8, node tree.mjs android printed:

defaults | grouped child: true | hidden banner: true | rows: 12
ignoreUnimportant | grouped child: true | hidden banner: false | rows: 12

On the iPhone 16 simulator, node tree.mjs ios printed:

defaults | grouped child: true | hidden banner: false | rows: 133

Grouping still changed what assistive technology receives. On iOS the container's label became the merged text of both children while each child reported accessible="false", and on Android the container became focusable.

Because the authors' 2025 setup and this run disagree, check your own build in Appium Inspector before grouping. Keep grouping to small composite controls such as a cart row, and leave it off list containers, where a screen reader would treat every row as a single stop.

Keep the Page Source Small

Every lookup and page-source call works through the native view tree, so a bigger tree makes those calls slower, as the runs below show. Long lists grow the tree fastest, because each row adds its own views.

FlatList vs ScrollView in Appium

React Native's ScrollView reference says it renders all its child components at once, while FlatList renders items lazily, when they are about to appear.

The FlatList optimization guide adds the details: windowSize is measured in viewport heights, 21 by default, and removeClippedSubviews, on by default only on Android, detaches off-screen views from the native hierarchy.

source-cost.mjs loads two copies of the test screen that differ in one line, a thousand rows in a FlatList or in a ScrollView, and times a page-source call with and without off-screen nodes:

// source-cost.mjs: page-source time, FlatList vs ScrollView
import { openDemo } from './demo.mjs';
const runs = [['FlatList  ', process.env.SNACK_URL],
  ['ScrollView', process.env.SNACK_SCROLLVIEW_URL]];
for (const [list, url] of runs) {
  const driver = await openDemo('android', url);
  await driver.pause(10000); // let 1,000 ScrollView rows finish rendering
  for (const all of [false, true]) {
    await driver.updateSettings({ allowInvisibleElements: all });
    const t0 = Date.now(), xml = await driver.getPageSource();
    console.log(list, all ? 'all rows ' : 'on screen', Date.now() - t0,
      'ms', (xml.match(/resource-id="item-\d/g) || []).length, 'rows');
  }
  await driver.deleteSession();
}

On the Pixel 8, node source-cost.mjs printed:

FlatList   on screen 951 ms 12 rows
FlatList   all rows  1105 ms 13 rows
ScrollView on screen 18426 ms 12 rows
ScrollView all rows  41659 ms 1000 rows

With default settings both lists returned the same 12 on-screen rows, yet the ScrollView call took about 18 seconds against under one second for FlatList, so mounted rows cost time even when Appium does not return them. Across four sessions the ScrollView call took between 15 and 19 seconds.

Turning on allowInvisibleElements returned all 1000 rows and took the call past 40 seconds.

On iOS, the tree.mjs run found 133 FlatList rows in the page source, so rows rendered below the fold were already in the XCUITest tree, unlike Android.

Reach Rows the List Has Not Rendered

On Android, a lookup for a row outside the render window fails until the list scrolls it into view. UiScrollable's scrollIntoView stops after 30 swipes by default, a limit set in AndroidX's UiScrollable source.

In an exploratory Pixel 8 session on Appium 2.2.1, scrolling toward item-500 stopped at rows 318 to 329 after 64.6 seconds. With setMaxSearchSwipes(100), a Galaxy S24 session on Appium 3.0.2 reached it after 141.5 seconds.

Bring the target near the top instead of scroll-searching in every test: type into the screen's search or filter field, or seed the test account with fewer items, then look the row up by its testID. Give every row a testID built from its key:

function Row({ item }) {
  return (
    <View testID={'item-' + item.id} style={styles.row}>
      <Text>{item.name}</Text>
    </View>
  );
}

// Inside App(): the FlatList that renders Row
  <FlatList
    testID="item-list"
    data={ITEMS}
    keyExtractor={(item) => item.id}
    renderItem={({ item }) => <Row item={item} />}
  />

Hide Decorative Views From the Tree

React Native's accessibility guide describes importantForAccessibility="no-hide-descendants" as forcing Android accessibility services to ignore a view and its children, and accessibilityElementsHidden as the iOS equivalent for VoiceOver. The test screen's banner sets both:

<View
  testID="hero-decoration"
  importantForAccessibility="no-hide-descendants"
  accessibilityElementsHidden={true}
  style={styles.box}>
  <Text testID="hero-decoration-text">Decorative banner</Text>
</View>

In the tree.mjs output, the banner was absent from the iOS tree but present on Android with default settings. It disappeared only after ignoreUnimportantViews, which the UiAutomator2 README describes as layout hierarchy compression, was set to true, so keep both props on decorative views for screen-reader users and treat the smaller Android page source as opt-in.

Austin Siewert

Austin Siewert

Co-Founder, Steadfast Systems

Discovered @TestMu AI yesterday. Best browser testing tool I've found for my use case. Great pricing model for the limited testing I do 👏

3M+ Devs and QAs rely on TestMu AI

Deliver immersive digital experiences with Next-Generation Mobile Apps and Cross Browser Testing Cloud

Appium Settings That Change the Page Source

The UiAutomator2 defaults below were read with getSettings() in this guide's Android sessions, and the XCUITest values come from the XCUITest driver's settings reference.

SettingDriverDefaultEffect when changed
disableIdLocatorAutocompletionUiAutomator2falsetrue stops the package prefix, so id matches a React Native testID.
allowInvisibleElementsUiAutomator2falsetrue adds off-screen and hidden nodes to the page source.
ignoreUnimportantViewsUiAutomator2falsetrue compresses the layout tree and drops views hidden from accessibility.
snapshotMaxDepthUiAutomator270Caps the tree depth; the driver accepts 1 to 500.
snapshotMaxDepthXCUITest50Caps the tree depth; lower values speed up source retrieval.
pageSourceExcludedAttributesXCUITestemptyLeaves the listed attributes out of the page source.
useJSONSourceXCUITestfalseFetches the source from WebDriverAgent as JSON and converts it to XML on the Appium server.

Older guides also tune XCUITest's customSnapshotTimeout, but the driver's changelog records its removal in version 8.0.0, released in January 2025.

Can AI Agents Automate React Native Testing Through MCP Servers?

Yes. An MCP server exposes Appium commands as tools an AI assistant calls from a natural-language request, and the Appium MCP README sets its lookup order: accessibility id, then id, then the platform's native strategy, with xpath last because it is slow and brittle.

On a React Native Android app, that order meets both traps from the earlier sections: accessibility id reads accessibilityLabel, and id gets the package prefix unless the session disables autocompletion. mobile-mcp, an MCP server for iOS and Android, also drives apps from the native accessibility tree and falls back to screenshots and coordinates only when needed, according to its README.

The same fixes serve agents: a unique testID on every element the agent should touch, a human accessibilityLabel, and the autocompletion setting in the capabilities that Appium MCP loads from its capabilities.json file. How Appium MCP works covers the setup, and if an AI coding agent writes your tests, the Appium skill for Claude Code gives it Appium patterns for TestMu AI devices; give it this guide's mapping too, because accessibility id behaves differently across platforms in React Native.

Run the Same Checks on Real Devices

TestMu AI App Automation runs Appium, Espresso, XCUITest, and Detox suites on 50,000+ real Android and iOS devices, plus cloud emulators and simulators. The isRealMobile option in session.mjs is the switch: set to true, the session runs on physical hardware, and without it the session runs on an emulator or simulator.

Sessions can record device logs, network logs, video, and screenshots, so a failed Android id lookup can be replayed against the recording of the run. React Native teams that prefer Detox can run those suites on App Automation as well, and Appium vs Detox compares the two frameworks.

For the screen-reader side, TestMu AI accessibility testing adds a hook to the same Appium session: with accessibility enabled in the capabilities, browser.execute('lambda-accessibility-scan') scans the current screen, as the WebdriverIO accessibility guide shows. The scan needs the accessibility entitlement on the account, and its results appear in the test dashboard.

Run iOS + Android tests written by your AI agent.

Appium

Conclusion

Run locators.mjs against your own build on one Android and one iOS device first. If the bare id misses on Android while the accessibility id matches on iOS, set disableIdLocatorAutocompletion and keep every testID out of accessibilityLabel. The TestMu AI real device cloud provides both devices, and the Appium getting-started guide covers uploading an APK or IPA and setting capabilities.

Co-authored with Sai Krishna, Director of Engineering at TestMu AI, a core contributor to the Appium open-source project and the creator of AppiumTestDistribution and appium-device-farm.

Testing from the terminal? Kane CLI by TestMu AI lets SDETs and developers plan, write, run and debug tests from the command line.

To run your first test, start free, or
for a full walkthrough of the product.

Author

...

Srinivasan Sekar

Blogs: 21

  • Twitter
  • Linkedin

Srinivasan Sekar is Director of Engineering at TestMu AI, where he leads engineering and open-source initiatives behind the Selenium and Appium automation grid and owns TestMu AI's MCP Server. A committer to Appium and a contributor to Selenium, WebdriverIO, Taiko, and AppiumTestDistribution, he brings over 15 years of experience in quality engineering and open-source technologies. He is the author of the Apress book 'The MCP Standard: A Developer's Guide to Building Universal AI Tools with the Model Context Protocol,' a Certified Kubernetes and Cloud Native Associate, and an international conference speaker. Before TestMu AI he spent over eight years at Thoughtworks as a Principal Consultant and Quality Architect. Srinivasan holds a B.Tech in Information Technology from Anna University.

Reviewer

...

Navin Chandra

Reviewer

  • Linkedin

Navin Chandra is a Member of Technical Staff at TestMu AI, building the open-source automation that powers its Selenium and Appium cloud grid. A committer to both Selenium and Appium, he implemented WebDriver BiDi support in Selenium for real-time browser events and bidirectional control and is developing Apple's iOS RemoteXPC protocol in Appium to enable low-level wireless communication with iOS system services. He contributes to Selenium across multiple language bindings as a member of the Selenium GitHub organization. He has served as a Google Summer of Code mentee and mentor at openSUSE and an LFX mentee at CNCF's KubeArmor, and is a SUSE Certified Deployment Specialist. Navin holds a B.Tech in Computer Science.

Add to Google preferred sources

Summarise with AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free

React Native testID FAQs

Did you find this page helpful?

More Related Blogs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests