Skip to content

Latest commit

 

History

History
107 lines (75 loc) · 3.33 KB

appium.md

File metadata and controls

107 lines (75 loc) · 3.33 KB

react native 使用 appium

Appium

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

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

Accessibility ID:

  • iOS 对应 accessibilityIdentifier
  • Android 对应 ContentDescription

React Native

使用 RN ViewtestID 或者 accessibilityLabel

iOS

  • accessibilityLabel 对应 accessibilityLabel
  • testID 对应 accessibilityIdentifier

RCTViewManager.m:

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

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

神策:

iOS

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

Android

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

References