Skip to content

Commit b2eff28

Browse files
author
Jayme Deffenbaugh
committed
Expose the testID to black-box testing frameworks on Android
1 parent 8d6b41e commit b2eff28

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo
246246
}
247247
}
248248
}
249+
250+
// Expose the testID prop as the resource-id name of the view. Black-box E2E/UI testing
251+
// frameworks, which interact with the UI through the accessibility framework, do not have
252+
// access to view tags. This allows developers/testers to avoid polluting the
253+
// content-description with test identifiers.
254+
final String testId = (String) host.getTag(R.id.react_test_id);
255+
if (testId != null) {
256+
info.setViewIdResourceName(testId);
257+
}
249258
}
250259

251260
@Override
@@ -425,7 +434,8 @@ public static void setDelegate(final View view) {
425434
if (!ViewCompat.hasAccessibilityDelegate(view)
426435
&& (view.getTag(R.id.accessibility_role) != null
427436
|| view.getTag(R.id.accessibility_state) != null
428-
|| view.getTag(R.id.accessibility_actions) != null)) {
437+
|| view.getTag(R.id.accessibility_actions) != null
438+
|| view.getTag(R.id.react_test_id) != null)) {
429439
ViewCompat.setAccessibilityDelegate(view, new ReactAccessibilityDelegate());
430440
}
431441
}

0 commit comments

Comments
 (0)