参考 Find Elements Appium 通过 AccessibilityId 找到元素
List<MobileElement> elementsOne = (MobileElement) driver.findElementsByAccessibilityId("SomeAccessibilityID");
Accessibility ID
:
- iOS 对应
accessibilityIdentifier
- Android 对应
ContentDescription
使用 RN View 的 testID
或者 accessibilityLabel
accessibilityLabel
对应accessibilityLabel
testID
对应accessibilityIdentifier
RCTViewManager.m
:
RCT_REMAP_VIEW_PROPERTY(accessibilityLabel, reactAccessibilityElement.accessibilityLabel, NSString)
RCT_REMAP_VIEW_PROPERTY(testID, reactAccessibilityElement.accessibilityIdentifier, NSString)
accessibilityLabel
对应ContentDescription
testID
对应Tag
BaseViewManager.java
:
private static final String PROP_ACCESSIBILITY_LABEL = "accessibilityLabel";
public static final String PROP_TEST_ID = "testID";
@ReactProp(name = PROP_ACCESSIBILITY_LABEL)
public void setAccessibilityLabel(T view, String accessibilityLabel) {
view.setContentDescription(accessibilityLabel);
}
@ReactProp(name = PROP_TEST_ID)
public void setTestId(T view, String testId) {
view.setTag(R.id.react_test_id, testId);
// temporarily set the tag and keyed tags to avoid end to end test regressions
view.setTag(testId);
}
$element_content
对应accessibilityLabel
[properties setValue:[uiView.accessibilityLabel stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] forKey:@"$element_content"];
$element_content
对应getText
Platform | System | ||
---|---|---|---|
React Native | JS | testID | accessibilityLabel |
React Native | iOS | accessibilityIdentifier | accessibilityLabel |
React Native | Android | Tag | ContentDescription |
Appium | iOS | AccessibilityId | - |
Appium | Android | - | AccessibilityId |
所以 Appium 在 React Native 中使用 AccessibilityId,必须同时设置 React Native 的 testID 和 accessibilityLabel 为同一值
- Is there any UI testing framework for React Native apps?
- Finding elements by Accessibility ID
- appium App 测试
- Selenium Web 测试
- Cavy react native 测试,react 方式获取 ref
- facebook/react-native#9942 appium 支持 react native 的讨论
- Appium + React Native Quickstart