Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use React Native's nativeID instead of testID #3724

Open
kellybind opened this issue Nov 21, 2022 · 3 comments
Open

Use React Native's nativeID instead of testID #3724

kellybind opened this issue Nov 21, 2022 · 3 comments

Comments

@kellybind
Copy link

Describe your idea

Hi there! We have a platform that uses React Native for both Android and iOS app, and we our switching our current desktop web setup to use React Native for Web (away from Angular). In web and html, the id is king (HTMLElement.id (https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id)) and is used extensively for both accessibility (unique identifiers) and test automation (being able to easily select elements by unique id). It would be extremely useful to be able to use the same IDs across all 3 apps, and not have to differentiate between needing to use testIDs vs nativeIDs or both. Using nativeIDs is obviously preferable since it equates to html IDs, and is not just code added "for testing", but is used as the unique identifier for both accessibility standards and test automation (including unit tests and QA functional tests). Are there any plans to be able to use nativeIDs with Detox? Thanks so much!

@d4vidi
Copy link
Collaborator

d4vidi commented Nov 27, 2022

Hey @kellybind. That's definitely an interesting take on development in the React Native world.

Using nativeIDs is obviously preferable since it equates to html IDs

I needed some research in order to understand how that could play out 😄
I see that - in the Android case at least, nativeID's are resolved to custom Android View tags (specified by the id.view_tag_native_id ID) - which can be queried on the native side using view.getTag(). They are also accessible using ReactFindViewUtil.find(). That makes it overall quite similar to test ID's, which are mapped to the default view-tag. I presume that iOS is largely equivalent.

I suppose that introducing native ID support boils down, then, to introducing a matching API equivalent to the Detox by.id(). It can be implemented in a similar way for Android and iOS.

Unfortunately, we do not have the capacity to take this any time soon. Discussion1-pending, we could definitely accept this as a contribution to Detox. If that sounds tangible, let us know and we could provide further refs 🙏🏻

Footnotes

  1. @wix/detox-team voice your opinion if you have anything to say about this.

@noomorph
Copy link
Collaborator

noomorph commented Jan 16, 2023

Why doesn't it translate to native accessibility properties? 🤔 Not sure if I understand. Could someone call device.captureViewHierarchy() on iOS and upload it here (+JSX fragment with that nativeID)?

@d4vidi
Copy link
Collaborator

d4vidi commented Jan 16, 2023

Why doesn't it translate to native accessibility properties? 🤔 Not sure if I understand. Could someone call device.captureViewHierarchy() on iOS and upload it here (+JSX fragment with that nativeID)?

It definitely might - on iOS. Android is a bit different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants