facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
117.7k stars 24.16k forks source link

[New Architecture] iOS - Unable to read Text attribute from TextInput with testId #38709

Closed ravindraguptacapgemini closed 3 weeks ago

ravindraguptacapgemini commented 1 year ago

Description

Recently after migrating to new architecture we are facing issue in locating TextInput in the automation test cases. Specifically we are not able to read the text value and the length of text of a TextInput element in Appium test cases.

What exactly happening here is that with new architecture is setting the specified testID to TextInput's direct parent view (refer screenshot - New Architecture - Value available on child of element with specified testID.png) instead of setting it directly to the TextInput (as it works in old architecture, screenshot - Old Architecture.png).

React Native Version

0.72.3

Output of npx react-native info

System: OS: macOS 13.4.1 CPU: (12) arm64 Apple M2 Pro Memory: 936.34 MB / 32.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 16.20.0 path: /usr/local/bin/node Yarn: version: 1.22.19 path: /opt/homebrew/bin/yarn npm: version: 8.19.4 path: /usr/local/bin/npm Watchman: version: 2023.06.26.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.12.1 path: /Users/ravindragupta/.rbenv/shims/pod SDKs: iOS SDK: Platforms:

Steps to reproduce

Add testId for TextInput and try to read text value from the element in automation test case (i.e. Appium)

Snack, code example, screenshot, or link to a repository

Old Architecture New Architecture - Value not available on element with specified testID New Architecture - Value available on child of element with specified testID

Reproducer App Link: https://github.com/ravindraguptacapgemini/reproducer-react-native-maps-events/tree/layout-animation-issue

ravindraguptacapgemini commented 1 year ago

@cortinico can you please check on this issue once, suggest if there is any quick workaround.

cortinico commented 1 year ago

can you please check on this issue once, suggest if there is any quick workaround.

I believe this is a bug, and sadly I don't have any quick workaround

ravindraguptacapgemini commented 1 year ago

@cortinico please provide a path to look for the possible issue, I will try to fix it myself.

ravindraguptacapgemini commented 1 year ago

@cortinico I am ready to contribute here, can you please give me a hint of area to look for possible bug.

ravindraguptacapgemini commented 1 year ago

@cortinico found out that now with new architecture, the testID is mapped to accessibilityIdentifier of a native component, previously it was being mapped to accessibilityLabel, that's why the Appium was not able find the element (with accessibility-id).

We were used to passed testID for iOS and accessibilityLabel for android but now have to used both for iOS, as:

export default function getAutomationID(automationID) {
 return Platform.OS === 'ios' ? { testID: automationID, accessibilityLabel: automationID } : { accessibilityLabel: automationID };
}

After all we have issue with multiple views in hierarchy specifying the same accessibilityLabel as in the screenshot:

Screenshot 2023-08-08 at 7 57 29 PM
umangdivyanshucapgemini commented 1 year ago

@ravindraguptacapgemini @cortinico Here is another issue that I have observed after fabric enablement. For some of the icons, the name/accessibility id has changed to special characters. Attaching screenshots for reference.

Before fabric enablement - image

After fabric enablement - image

umangdivyanshucapgemini commented 1 year ago

@cortinico Just checking if you got some time to check this? We are getting these issues throughout the application after the fabric upgrade. In addition to these issues, after setting the accessibility label we were able to find out the elements but the element's text is returning the accessibility id itself.

driver.find_element(:accessibility_id, 'urlField').text

image

Instead of "https://" we are getting "urlField"

ravindraguptacapgemini commented 11 months ago

@cortinico Do we have some update on this issue?

cortinico commented 11 months ago

@cortinico Do we have some update on this issue?

Nope I'm sorry

ravindraguptacapgemini commented 10 months ago

@cortinico We have seen the child components are being arranged as siblings in the Dom hierarchy, does it has something to do with View Flattening or it's a bug in react native new architecture?

ravindraguptacapgemini commented 9 months ago

@cortinico Do we have some update on this issue?

Nope I'm sorry

Are you checking on these issues related to accessibility and end-to-end test, because there are lots of issues regarding locating elements. I know we are going to get major release 0.73, but can you please target to fix this issue in the coming releases?

gedeagas commented 5 months ago

Related Issues https://github.com/facebook/react-native/issues/43648

cortinico commented 2 months ago

This is probably fixed by:

Need to be cross checked in 0.75 and eventually closed.

blakef commented 1 month ago

I've reproduced this and confirmed it's a New Architecture specific issue. Fix on the way.

cortinico commented 3 weeks ago

Fixed by https://github.com/facebook/react-native/pull/45379