Android resource-id generated from testID not contains package name
See original GitHub issueDescription
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
- Define component
<Pressable testID="e2e_tid">
<Text>Hello There</Text>
</Pressable>
- Build the app
- 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>
testID
without any prefix (Current Behaviour)
<Pressable testID="e2e_tid">
<Text>Hello There</Text>
</Pressable>
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:7 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @keremoge will test this out with the latest RN and latest Appium. Just give me a couple of days.
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.