requireTestId method

String requireTestId(
  1. ElementTarget target
)

TestId for direct step-executor dispatch only.

Does not pre-resolve the widget — TestStepExecutor waits/polls with the step's timeoutMs. Snapshot / occurrence targets must use resolveFinder instead so identity is preserved.

Implementation

String requireTestId(ElementTarget target) {
  if (target.usesSnapshotElement) {
    throw const TestExecutionError(
      code: TestExecutionErrorCode.unsupportedAction,
      message: 'Snapshot elementId targets must use exact Element identity; '
          'they cannot be remapped to testId.',
    );
  }
  if (target.occurrence != null) {
    throw const TestExecutionError(
      code: TestExecutionErrorCode.unsupportedAction,
      message: 'occurrence targeting must use the resolved Finder path; '
          'it cannot be remapped to a bare testId.',
    );
  }
  final locator = target.normalizedLocator;
  final testId = target.testId ?? locator?.id;
  if (testId == null || testId.isEmpty) {
    throw const TestExecutionError(
      code: TestExecutionErrorCode.unsupportedAction,
      message: 'This operation requires an id locator.',
    );
  }
  return testId;
}