readWidgetLocatorId function

String? readWidgetLocatorId(
  1. Element element
)

Locator id for YAML testId: / id: as shown on an observed control.

Priority: testId (ValueKey) first; YAML id (Invokable.id) only when this element itself has no testId key.

Finders use finderForLocatorId (ValueKey / testId only). Ensemble already mirrors YAML id: onto a KeyedSubtree ValueKey via the controller testId getter, so steps must wait for that key — matching bare Invokable too early (before State builds the KeyedSubtree) caused mid-transition taps and framework build-scope errors.

Prefer observeLocatorId when attaching testId on observation / report rows — this helper inherits any ancestor id (including page shells).

Implementation

String? readWidgetLocatorId(Element element) {
  final direct = readOwnedWidgetLocatorId(element);
  if (direct != null) return direct;
  return nearestOwnedLocatorIdAncestor(element);
}