我想使用Firebase TestLab,但似乎它只能以资源ID为目标。我的元素是这样的:
<Input {...props} testID="usernameIput" />
但似乎testID没有映射到resource-id。如果这不是实现的方法,那么我怎样才能在react-native中访问resource-id?如果不能,有什么绕过方式可以在Android Studio中添加resource-id吗?
我想使用Firebase TestLab,但似乎它只能以资源ID为目标。我的元素是这样的:
<Input {...props} testID="usernameIput" />
但似乎testID没有映射到resource-id。如果这不是实现的方法,那么我怎样才能在react-native中访问resource-id?如果不能,有什么绕过方式可以在Android Studio中添加resource-id吗?
虽然我来晚了将近4年,但从React Native 0.64版本开始,testId
属性现在映射到Android构建中的resource-id
,这意味着依赖于此属性的Android测试框架将正确运行。
以前使用的accessibleLabel
的解决方法不应该继续使用,因为它会破坏可访问性。更多关于此更改的理由可以在此处找到。
testId
还有很长的路要走。 - alwaysday1在视图上同时使用accessible
和accessibleLabel
(目前来看,这对View、Text和TextInput有效),UiAutomator将从accessibleLabel
生成content-desc
字段。
目前,我们可以使用content-desc来标识标签。
有关可访问性标签的文档:https://facebook.github.io/react-native/docs/accessibility.html#accessibilitylabel-ios-android。
<Text
testID="btnText" //works for iOS
accessibilityLabel="btnText" //works for android & iOS content-description
accessible
>
{text}
</Text>
尝试进行调试构建。此解决方案是在这里提出的。
您可以使用此处的答案进行调试构建:
#React-Native 0.49.0+
react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
#React-Native 0-0.49.0
react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
然后在打包后构建APK:
$ cd android
#Create debug build:
$ ./gradlew assembleDebug
#Create release build:
$ ./gradlew assembleRelease #Generated `apk` will be located at `android/app/build/outputs/apk`