Uh oh!
There was an error while loading. Please reload this page.
[e2e-testing][Appium] Adding support for android:id - #9942
Conversation
ghost
commented
Sep 16, 2016
By analyzing the blame information on this pull request, we identified @kmagiera and @sebmarkbage to be potential reviewers. |
jsdevel
commented
Sep 16, 2016
@ide what's the best way I could test this change? |
ide
commented
Sep 17, 2016
Building from source and running the UIExplorer + temporarily modifying its code to invoke your new code is a reasonable path forward. |
Thanks @ide ! I've verified locally that it works! |
I've also verified that non-existent ids in |
738f346 to
580888eCompare580888e to
ee453d3Comparejsdevel
commented
Sep 19, 2016
Looks like the tests for HMR are failing on most PRs. |
bestander
commented
Sep 19, 2016
Yeah, trunk was broken over weekend. |
There was a problem hiding this comment.
isn't this and line 94 checking the same thing? can you combine this logic?
There was a problem hiding this comment.
view.getResources().getIdentifier(testId, "id", view.getContext().getPackageName()) will return 0 if no matching identifier is found. I wanted to avoid calling it more than once for a given testID if possible which is why there are 2 checks:
- The first check is for caching purposes.
- The second check is to avoid setting the testId on the View if the user didn't define it.
I'm pretty wary of setting the ids on views because we at least use the ids of the ReactRootViews to track the ReactRootViews so this can break something in a hard to track way... |
4a9cf22 to
e406eb9Comparejsdevel
commented
Sep 19, 2016
|
e406eb9 to
5a61912Compare@AaaChiuuu I added an additional check to avoid setting the id on the View if it currently has an Id. |
5a61912 to
62f66dbCompare62f66db to
85dee1dComparejonestheguitar
commented
Apr 26, 2017
|
jsdevel
commented
Apr 26, 2017
I see. That's pretty cool in the sense that it |
jonestheguitar
commented
Apr 27, 2017
@jsdevel Good that you now understand it but painful that I had to spend so much time convincing you. I suggest next time you keep more of an open mind - you could easily have spent a few minutes trying the workaround for yourself rather than repeatedly shooting it down with unhelpful comments like "There's no way that works" just because you didn't understand it. |
@jonesdar It's quite possible that others will have similar questions. I wasn't trying to be difficult. Sorry if my questions caused you some consternation. You helped me to understand something about appium that I haven't seen documented anywhere and for that I am grateful.
In case any testing library authors are reading this, the method is findViewWithTag. |
skovhus
commented
May 3, 2017
@mkonicek is this still down prioritized? |
curioustechizen
commented
May 17, 2017
@jonesdar Thanks for this work-around! Just to point out, I had to use the plural forms of the locator methods for Appium to be able to find my view with the accessibilityLabel on Android: i.e., Using the plural form is apparently what tells Appium to try multiple strategies. The clue was in the Appium server debug logs. When I used the singular form, the log had the equivalent of
The |
voidgit
commented
Sep 26, 2017
@mkonicek Are there any plans to proceed with this issue? |
marlenabowen
commented
Dec 13, 2017
@mkonicek any ETA for when FB might open-source the internal e2e framework? |
kholiavko-roman
commented
Jan 22, 2018
Can I now to set resource-id for android from react-native ? |
ThaJay
commented
Jan 23, 2018
I'm afraid not. This should have been handled / merged months ago. |
Hey everyone, so sorry about the long radio silence about this. I left fb in the meantime and went traveling for 4 months and then joined a startup where I'm doing some native Android dev for now, currently playing with integrating React Native to an existing native app. I feel very sorry about closing this PR and seeing it disappointed so many people. I thought someone from the community would provide a way to look up elements by Android view tags like we did at fb and the issue would be solved. It looks like it's harder to add support to Appium than I thought, but will happen eventually (see appium-espresso-driver, found via a comment on the Appium issue). At the same time, I'm glad there is the workaround by @jonesdar (#9942 (comment)). To me it looks like a reasonable workaround and I'd use it when testing my app with Appium. I'll copy it here to make it easier to discover (at the end of the comments section). Quoting @jonesdar:
|
Worth pointing out that the workaround needs a few tweaks on newer versions of Android. Then you'll notice that waitForElementById, elementById etc. no longer do multiple locator strategy fallbacks (so elementById won't fall back to elementByAcessibilityId etc.) - I fixed that as follows: i.e. centrally map waitForElementById() to waitForElementByAccessibilityId() etc. - to ensure that Appium finds the testIDs we've put into the accessibilityLabels. I think I read somewhere that you can do multiple locator strategy fallbacks by using plurals (waitForElementsById, elementsById etc.) but I haven't tried that - and it would still require a global find/replace in all test code (or a central mapping as above) anyway to get existing tests working again. On the plus side, uiautomator2 seems to run my tests twice as fast as uiautomator. |
jsdevel
commented
Feb 8, 2018
I'd happily get this working again 😄 any takers from the RN team? |
jribeiro
commented
Feb 22, 2018
I've written a babel plugin to address this issue in the meantime. The idea is to add a property Hope it helps |
I realize that my pull request is very similar to this pull request. |
jsdevel
commented
Mar 23, 2018
@lightboys22 I'm sorry that you went down this road. I feel your pain 😢 |
Mishan999
commented
Mar 29, 2018
Good |
We use Appium to test our applications and I was able to solve this problem very elegantly with react-native-testid. |
@tylermurry react-native-testid will change the accessibilityLabel on Android platform. Our accessibilityLabels won't be unique. |
Frank1234
commented
Jul 4, 2018
A copy and paste solution using Espresso and the solution from #9942 in this article: |
jdeff
commented
Aug 26, 2020
I know this ticket is old and many people have found suitable workarounds, but in case anyone still cares (and is actually using |
sasmit
commented
Apr 15, 2021
@jdeff Am I missing something here ? |
thanveershah
commented
Apr 18, 2021
Same, resource-id is still empty, any solution yet for this? |

idresource needs to be manually added toandroid/app/src/main/res/values/ids.xml. Here's the contents of that file: