1. react native 使用 appium

1.1. Appium

参考 Find Elements Appium 通过 AccessibilityId 找到元素

List<MobileElement> elementsOne = (MobileElement) driver.findElementsByAccessibilityId("SomeAccessibilityID");

Accessibility ID:

  • iOS 对应 accessibilityIdentifier
  • Android 对应 ContentDescription

1.2. React Native

使用 RN ViewtestID 或者 accessibilityLabel

1.2.1. iOS

  • accessibilityLabel 对应 accessibilityLabel
  • testID 对应 accessibilityIdentifier

RCTViewManager.m:

RCT_REMAP_VIEW_PROPERTY(accessibilityLabel, reactAccessibilityElement.accessibilityLabel, NSString)
RCT_REMAP_VIEW_PROPERTY(testID, reactAccessibilityElement.accessibilityIdentifier, NSString)

1.2.2. Android

  • 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);
}

1.3. 神策:

1.3.1. iOS

  • $element_content 对应 accessibilityLabel
[properties setValue:[uiView.accessibilityLabel stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] forKey:@"$element_content"];

1.3.2. Android

  • $element_content 对应 getText

1.4. 结论

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 为同一值

1.5. References

results matching ""

    No results matching ""