execute method

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

Executes the test step. If the scrollableId is set then this will get that Scrollable instance and interact with it. Otherwise, this will attempt to find the first Scrollable instance currently in the viewport and interact with that.

For the most part, pages with a single Scrollable will work fine with omitting the scrollableId. However pages with multiple Scrollables (like a Netflix style stacked carousel) will require the scrollableId to be set in order to be able to find and interact with the inner Scrollable instances.

The timeout defines how much time is allowed to pass while attempting to scroll and find the Testable identified by testableId.

Implementation

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

  final name = "$id('$testableId', '$dx', '$dy')";
  final timeout = this.timeout ?? tester.delays.defaultTimeout;
  log(
    name,
    tester: tester,
  );

  final finder = await waitFor(
    testableId,
    cancelToken: cancelToken,
    tester: tester,
    timeout: timeout,
  );

  final evaluated = finder.evaluate();
  if (evaluated.length > 1) {
    var error =
        '[ERROR]: found (${evaluated.length}) widgets; expected only one.';
    var index = 0;
    for (var w in evaluated) {
      error += '\n  ${++index}: ${w.widget.runtimeType} [${w.widget.key}]';
    }
    throw Exception(error);
  }

  await driver.drag(finder, Offset(dx, dy));
}