execute method

  1. @override
Future<void> execute({
  1. required CancelToken cancelToken,
  2. required TestReport report,
  3. required TestController tester,
})
override

Executes the test step by ensuring the Testable with the given id exists on the widget tree before continuing. This will throw an error is the Testable with the set testableId cannot be found on the tree before the timeout is exceeded.

Implementation

@override
Future<void> execute({
  required CancelToken cancelToken,
  required TestReport report,
  required TestController tester,
}) async {
  final testableId = tester.resolveVariable(this.testableId);
  assert(testableId?.isNotEmpty == true);

  final name = "$id('$testableId')";
  log(
    name,
    tester: tester,
  );
  final finder = await waitFor(
    testableId,
    cancelToken: cancelToken,
    tester: tester,
    timeout: timeout,
  );

  await sleep(
    tester.delays.postFoundWidget,
    cancelStream: cancelToken.stream,
    tester: tester,
  );

  if (cancelToken.cancelled == true) {
    throw Exception('[CANCELLED]: step was cancelled by the test');
  }
  final widgetFinder = finder.evaluate();
  if (widgetFinder.isNotEmpty != true) {
    throw Exception('testableId: [$testableId] -- could not locate widget.');
  }
}