React Native + Appium iOS elementByAccesibilityId.text() [英] React Native + Appium iOS elementByAccesibilityId.text()

查看:26
本文介绍了React Native + Appium iOS elementByAccesibilityId.text()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Appium + Jest 为 Android 和 iOS 编写 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>

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

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: trueaccessibilityLabel 应该可以解决问题.但是:你不能只设置它们.如果 accessibilityLabeltestID 都设置了,它将不再适用于 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.

这篇关于React Native + Appium iOS elementByAccesibilityId.text()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆