反应本机+ Appium iOS iOS elementByAccesibilityId.text() [英] React Native + Appium iOS elementByAccesibilityId.text()
问题描述
我正在为Android和iOS使用Appium + Jest为React Native编写测试.
I'm writing tests for React Native using Appium + Jest for both Android and iOS.
这是我的React Native元素:
Here's my React Native element:
<Text accessibilityLabel={'emailError'}>Invalid email</Text>
这是我创建的Promise链,用于提取React Native Text
元素的值:
Here's the Promise chain I created to extract the value of a React Native Text
element:
driver.elementByAccessibilityId('emailError')
.then(error => error.text())
.then(errorText => expect(errorText).toBe('Invalid email'))
在Android上,此测试通过.在iOS上,此测试失败,并且errorText === 'emailError'
.
On Android, this test passes. On iOS, this test fails, and errorText === 'emailError'
.
这是为什么,并且有一种可以跨平台提取文本的解决方案吗?
Why is this, and is there a solution that works cross-platform for extracting text?
推荐答案
我遇到了同样的问题.在iOS上,使用testID
代替accessibilityLabel
可以为我工作.对于Android,accessible: true
和accessibilityLabel
应该可以解决问题.但是:您不能仅将它们全部设置.如果同时设置了accessibilityLabel
和testID
,则将无法再在iOS上运行.
I had the same issue. Using testID
instead of accessibilityLabel
worked for me on iOS. For Android, accessible: true
and accessibilityLabel
should do the trick. But: You can't just set them all. If accessibilityLabel
and testID
are both set, it won't work on iOS anymore.
iOS示例:
<Text testID={'emailError'}>Invalid email</Text>
Android示例:
Example for Android:
<Text accessible={true} accessibilityLabel={'emailError'}>Invalid email</Text>
像> https://github.com/tipsi/react-native-testid 可以帮助您基于平台设置正确的属性.
A library (or just create your own function) like https://github.com/tipsi/react-native-testid can help you with setting the correct attributes based on the platform.
这篇关于反应本机+ Appium iOS iOS elementByAccesibilityId.text()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!