reactjs - React Native + Appium iOS elementByAccessibilityId.text() 方法

标签 reactjs react-native appium jestjs e2e-testing

我正在使用 Appium + Jest 为 Android 和 iOS 编写 React Native 测试。

这是我的 React Native 元素:

<Text accessibilityLabel={'emailError'}>Invalid email</Text>

这是我为提取 React Native Text 元素的值而创建的 Promise 链:

driver.elementByAccessibilityId('emailError')
      .then(error => error.text())
      .then(errorText => expect(errorText).toBe('Invalid email'))

在 Android 上,此测试通过。在 iOS 上,此测试失败,并且 errorText === 'emailError'

这是为什么,是否有跨平台的解决方案来提取文本?

最佳答案

我遇到了同样的问题。使用 testID 而不是 accessibilityLabel 在 iOS 上对我有用。对于 Android,accessible: trueaccessibilityLabel 应该可以解决问题。但是:你不能只设置它们。如果同时设置了 accessibilityLabeltestID,它将不再适用于 iOS。

iOS 示例:

<Text testID={'emailError'}>Invalid email</Text>

Android 示例:

<Text accessible={true} accessibilityLabel={'emailError'}>Invalid email</Text>

https://github.com/tipsi/react-native-testid 这样的库(或创建您自己的函数)可以帮助您根据平台设置正确的属性。

关于reactjs - React Native + Appium iOS elementByAccessibilityId.text() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51642256/

相关文章:

使用状态或 Prop 进行 ReactJS 渲染

javascript - 提升一个状态,以便我可以使用 onPress 对其进行修改

css - 是否可以在 ReactJS 中的表格单元格上设置 CSSTransitionGroup?

javascript - 为什么 exponentpush token 为空

android - Android 上的 Appium 无法定位在屏幕滚动部分不可见的元素

javascript - React.js 从 AWS 读取用户信息并设置变量状态

javascript - react-native-dropdown-picker 列出的项目未正确显示(叠加)

react-native - 日期未正确保存在 react-native Realm

IOS测试: Test interaction between two apps

android - 如何进行非常基本的 AWS Device Farm 应用程序端到端测试 : Just Run the App for Specified Time