Skip to content

Commit

Permalink
Expose the testID to black-box testing frameworks on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayme Deffenbaugh committed Aug 10, 2020
1 parent 8d6b41e commit b2eff28
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo
}
}
}

// Expose the testID prop as the resource-id name of the view. Black-box E2E/UI testing
// frameworks, which interact with the UI through the accessibility framework, do not have
// access to view tags. This allows developers/testers to avoid polluting the
// content-description with test identifiers.
final String testId = (String) host.getTag(R.id.react_test_id);
if (testId != null) {
info.setViewIdResourceName(testId);
}
}

@Override
Expand Down Expand Up @@ -425,7 +434,8 @@ public static void setDelegate(final View view) {
if (!ViewCompat.hasAccessibilityDelegate(view)
&& (view.getTag(R.id.accessibility_role) != null
|| view.getTag(R.id.accessibility_state) != null
|| view.getTag(R.id.accessibility_actions) != null)) {
|| view.getTag(R.id.accessibility_actions) != null
|| view.getTag(R.id.react_test_id) != null)) {
ViewCompat.setAccessibilityDelegate(view, new ReactAccessibilityDelegate());
}
}
Expand Down

0 comments on commit b2eff28

Please sign in to comment.