question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android resource-id generated from testID not contains package name

See original GitHub issue

Description

I am working on writing black-box E2E tests for React Native App.
For targeting elements, I am using testID in JS world which translates to resource-id in Android and name in iOS.

The resource-id generated from testID is not prefixed with the name of the package. Due to which appium is not able to find elements by resouce-id. Works fine in iOS.

Current Behaviour testID = "abcd" => resource-id = "abcd"

Expected testID = "abcd" => resource-id = "com.myawesomeapp:id/abcd"

Refer this -> https://github.com/appium/appium/issues/15354#issuecomment-836679925

React Native version:

System:
    OS: macOS 11.5.2
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 998.38 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.16.1/bin/yarn
    npm: 6.14.12 - ~/.nvm/versions/node/v14.16.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7199119
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.11 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.65.1 => 0.65.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Define component
<Pressable testID="e2e_tid">
    <Text>Hello There</Text>
</Pressable>
 
  1. Build the app
  2. Use appium desktop or any other tool to probe the render tree.

Expected Results

testID with explicitly defined prefix. (Expected)

  <Pressable testID="com.rncliappium:id/e2e_tid">
      <Text>Hello There</Text>
  </Pressable>

https://user-images.githubusercontent.com/32242596/134005310-99a883b6-de31-4feb-ae50-2d0203a9b280.mov

testID without any prefix (Current Behaviour)

  <Pressable testID="e2e_tid">
      <Text>Hello There</Text>
  </Pressable>

https://user-images.githubusercontent.com/32242596/134005523-53bef6ae-be02-489b-9cb5-881337ba8f2e.mov

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
pranshuchittoracommented, May 12, 2022

Hi @pranshuchittora, Does the issue still persists? Can you please share your environment for Android? Appium with UIAutomator2 or Espresso?

Hey @keremoge will test this out with the latest RN and latest Appium. Just give me a couple of days.

3reactions
tuncaulubilgecommented, Nov 2, 2021

To add a bit of context, Android requires resource-ids to be unique amongst all packages, so it’s best practice to prefix it with the bundle identifier. That’s why Appium has opted in to use this prefix. See: https://github.com/appium/appium/issues/15354#issuecomment-865048105

For the time being, a solution like this could be used to manually add that prefix to every testID (see: https://dev.to/nextlevelbeard/an-end-to-the-abuse-of-accessibility-ids-5d2j), but we should really have this solution as part of React Native.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add resource-id to android in react-native
Show activity on this post. But it seems that the testID is not mapped to the resource-id. If this is not the way...
Read more >
An end to the abuse of Accessibility IDs - DEV Community ‍ ‍
It seems Appium requires the package name to be part of the resource-id itself otherwise it will fail to find it. If your...
Read more >
React-Native and unique identifiers - TIPS AND TRICKS
React-Native supports an attribute called testID for Views. Through Appium, this testID attribute is exposed directly as "name" when working with iOS. In...
Read more >
Testing your Compose layout - Jetpack - Android Developers
Semantics. UI tests in Compose use semantics to interact with the UI hierarchy. Semantics, as the name implies, give meaning to a piece ......
Read more >
We are facing issue where “testID” is not mapped to “resource ...
We are facing issue where “testID” is not mapped to “resource-id” for android and therefore we are not able to use that in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found