finderForTarget method

Finder finderForTarget(
  1. ElementTarget target, {
  2. required String operationName,
  3. bool requireInteractive = true,
  4. bool allowEmpty = false,
  5. bool allowOffscreen = false,
})

Implementation

Finder finderForTarget(
  ElementTarget target, {
  required String operationName,
  bool requireInteractive = true,
  bool allowEmpty = false,
  bool allowOffscreen = false,
}) {
  final resolve = resolveTargetFinder();
  final needsExactResolution =
      target.locator != null || target.usesSnapshotElement;
  if (resolve != null &&
      (needsExactResolution || requireInteractive || allowEmpty)) {
    // The session resolver validates ambiguity and preserves occurrence or
    // snapshot identity, including simple testId targets. Falling back to a
    // key finder here can match several widgets and fail later in
    // ensureVisible with an unhelpful StateError.
    return resolve(
      target,
      requireInteractive: requireInteractive,
      allowEmpty: allowEmpty,
      allowOffscreen: allowOffscreen,
    );
  }
  if (needsExactResolution) {
    throw EnsembleTestFailure(
      'Operation "$operationName" requires a session target resolver.',
    );
  }
  final id = target.testId;
  if (id == null || id.isEmpty) {
    throw EnsembleTestFailure(
      'Operation "$operationName" requires "id" or "target"',
    );
  }
  return assertions.finderForId(id, skipOffstage: requireInteractive);
}