wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.15k stars 1.92k forks source link

Use React Native's nativeID instead of testID #3724

Open kellybind opened 1 year ago

kellybind commented 1 year ago

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 commented 1 year ago

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. Discussion[^1]-pending, we could definitely accept this as a contribution to Detox. If that sounds tangible, let us know and we could provide further refs 🙏🏻

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

noomorph commented 1 year ago

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 commented 1 year ago

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.