Finding by accessibility id doesn’t work for React Native View testID - it works for accessibilityLabel but that’s a user-facing string (e.g. read out by TalkBack) so I’d prefer not to put test ids in there.
So I don’t think that comment is correct - in the methods themselves you’ll see that Android View.getTag() and setTag() are used so unless that propagation is done somewhere else the comment is definitely wrong.
Also I’m not sure if it’s the correct thing to do anyway - if the tag value gets propagated via View.setContentDescription() then we’re again in the territory of test ids being exposed to users.
Content descriptions on Android are always user facing. You might want to ask the react team how you’d find a testID with uiautomator, then you could do the same with appium.
I guess the React Native team used the tag because it’s one of the few non user-facing places in View to store custom data.
I don’t think uiautomator can find by tag so presumably their automated tests use something that can (e.g. Calabash).
Any thoughts for workarounds in Appium? I could add test ids via accessibilityLabel for testing and then remove them for production but that’s cumbersome and also kind of goes against the Appium ethos.
Appium is in the process of upgrading to uiautomator v2 which can find by tags because we have the full instrumentation API available. It’ll probably take a very long time to be ready though. In uiautomator v1 (what appium currently uses), this isn’t possible.
The only work around I know of is exactly what you mentioned, strip the automaton only content descriptions out of production builds.
Would that need modifications to React Native? I don’t think there’s currently a way to specify the resource id of the Android View that backs a React Native View so it might need a new property (can’t use the testID because that’s a string and Android View.setId() takes an int).
Yes, you’d need the setId method to be exposed. Also you’d need a resource reference (what the int refers to). I don’t think arbitrary ints would work well.
One workaround you could do is to set accessibilityLabel to a conditional value depending if you are building for debug or production (or just have some global flag to indicate that). While not ideal, it will minimize code changes and will allow you to access elements for testing.
However, I would like to ask you a related question… I was not able to set accessibilityLabel which could map to content description for Inputs and Buttons (TouchableHighlight / TouchableOpacity elements). I could see content-desc field in UI Automator for other elements but not for anything actionable. Have you been able to see / access those elements in your test??
It is a bug in react native.
In their code they left out accessibilityLabel
I submit a PR to add it
In the mean while my question for Appium team. @bootstrap
There is no accessibilityIdentifier equivalent on Android. What is the best strategy to set some id-type string to locate elements without messing with content description?
release/debug build is an option but not ideal.