facebook / react-native

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

[Android] TestID assigned to TextInput control not working #32969

Open anchitkoul opened 2 years ago

anchitkoul commented 2 years ago

Description

Adding TestID on Android platform to TextInput does not show up in Appium Inspector or Appium tests.

"react": "^16.12.0", "react-native": "^0.64.3",

Appium Doctor v.1.15.3

Version

16.12.0

Output of npx react-native info

System: OS: macOS 10.15.7 CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz Memory: 36.09 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 16.2.0 - /usr/local/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 7.13.0 - /usr/local/bin/npm Watchman: 2021.11.08.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: API Levels: 30 Build Tools: 28.0.3, 29.0.3, 32.0.0 System Images: android-30 | ARM 64 v8a, android-30 | Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom_64 Android NDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7935034 Xcode: 12.4/12D4e - /usr/bin/xcodebuild Languages: Java: 1.8.0_292 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: Not Found react-native: ^0.64.3 => 0.64.3 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

  1. Add Test ID to TextInput component
  2. Open app on Android Emulator
  3. Open Appium inspector to inspect this component / Write Appium test to inspect this component

Expected: testID value should be present in ID attribute of the component. Result : testID value is not present in ID attribute

import { TextInput } from 'react-native';

<TextInput
      testID={item.testID}
      editable={!disabled}
      maxLength={maxLength}
      accessibilityLabel={ariaLabel}
      onChangeText={onChangeText}
      selectionColor={colorMapping.blue}
      style={[composedStyle.textbox, isiOS && !innerLabel ? {} : innerLabelBorderStyle]}
      underlineColorAndroid='transparent'
      onFocus={onFocus}
      onBlur={onBlur}
      value={value}
      accessibilityLabel={ariaLabel}
 />

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

No response

rguerra712 commented 2 years ago

Anyone by chance have a workaround for this? We are suffering from the same problem.

OksanaHanailiuk commented 2 years ago

Hey guys, I am faced with the same problem? Any progress on this? Thanks

jennifer-dickinson commented 2 years ago

Also experiencing this same issue.

anchitkoul commented 2 years ago

is someone looking into this issue?

keremoge commented 2 years ago

I think using UIAutomator2 or Espresso for Appium on Android won't be able to set ID even if you set TestID, but if You use accessibilityLabel for Android, then you can use accessibilityId which is faster like accessing ID. Be careful because accessibilityLabel is also used for accessible apps for blind people

anchitkoul commented 2 years ago

Thats exactly the reason we don't want to use accessibilityLabel , our organization takes accessibility very seriously

keremoge commented 2 years ago

Thats exactly the reason we don't want to use accessibilityLabel , our organization takes accessibility very seriously

Actually there is a commit related to this issue but I didn't test it. I think with RN version 0.65 you can use TestID on Android. If your version is older than 0.65, can you upgrade your react-native and then try Android TestID with both UIAutomator2 and Espresso?

related topics: 381fb395ad9d2d48717a5d082aaedbecdd804554 https://github.com/facebook/react-native/pull/29610

anchitkoul commented 2 years ago

has anyone seen it working in 0.65+ version?

brett-james-rocketlab commented 2 years ago

No, although if you give your testid a globally unique name it can: testID='com.your.app:id/password'

siebertm commented 2 years ago

on v0.66, testID works mostly, but not for TextInput! It seems that it's simply not setting resource-id for andoid (works fine on ios)

diego-epicura commented 2 years ago

on v0.66, testID works mostly, but not for TextInput! It seems that it's simply not setting resource-id for andoid (works fine on ios)

Same here, any workarounds?

chetstone commented 1 year ago

PR #31865 was supposed to fix this but I'm not having any luck on RN 0.70.5

brett-james-rocketlab commented 1 year ago

Did you try a globally unique test id? because on Android you need it to be unique, https://github.com/facebook/react-native/issues/32969#issuecomment-1286399395 . Does it still not work with that?

chetstone commented 1 year ago

@brett-james-rocketlab Thanks for your reply. I did see your comment and I thought something like io.malamode.signInUser would be good enough to make it globally unique but it didn't work.

After running the test, I got the message

Unused text input: no resource name matched the regex "io.malamode.signInUser"

I'm trying to test using firebase-test-lab rather than one of the other tools mentioned in this thread. I just tried something closer to the exact format you mention in your example: io.malamode:id/user but when I try to enter that in the test account credentials field in the Test Lab Presets setup, I get the message: Invalid character ':'

So I'm not sure how to make it globally unique, if that's what the problem is. I wonder if it has anything to do with it treating the resource ID as a regex?

brett-james-rocketlab commented 1 year ago

@chetstone Ok you sound like you've done all the right things there then. What you can also do is launch appium + appium inspector (it can take a bit to setup - the. goal is to be able to see a representation of what your app is rendering): , and then confirm what you are setting is appearing there - this is because you'll see the field you've added, including it's xpath. You should expect to see your testid etc to appear there.

shankarRxo commented 1 year ago

Suffering from the same problem.

tobywisener commented 1 year ago

Suffering for the same problem, but also for View's, TextInputs etc

anatooly commented 10 months ago

Unused text input: no resource name matched the regex "email"

not work too <TextInput testID="email" /> "react-native": "0.72.7", and "react-native": "0.73.4"

shubhamdeol commented 6 months ago

anyone tested this in react-native:0.74 ?

react-native-bot commented 6 days ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

brett-james-rocketlab commented 6 days ago

This would be good to see resolved. I'll try spin up a v0.76.x build this week - fabric renderer might make this more tricky.

Since I first filed this, I moved from Appium, to Maestro Studio for testing because its much more flexible at handling this.