containerScopeLocator function

ElementLocator? containerScopeLocator(
  1. UiElement element
)

within= scope for descendants — includes non-tappable cards/toasts.

Gesture cheapSuggestedLocator stays null on inert cards (no sel), but nested rating icons still need within={label, role=card}, role=icon.

Implementation

ElementLocator? containerScopeLocator(UiElement element) {
  final id = _nonEmpty(element.testId);
  if (id != null) return ElementLocator(id: id);

  final type = (element.type ?? '').toLowerCase();
  final caption = _firstLineCaption(_nonEmpty(element.label)) ??
      _firstLineCaption(_nonEmpty(element.text));
  if (caption == null || !_isSupportedLocatorRole(type)) return null;

  switch (type) {
    case 'card':
    case 'toast':
    case 'button':
      return ElementLocator(label: caption, role: type);
    default:
      return null;
  }
}