execute method

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

Iterates through all active Testable widgets that have an id that matches the given regEx, sets the id in variableName (or _testableId if no variableName is set) and calls the step.

Implementation

@override
Future<void> execute({
  required CancelToken cancelToken,
  required TestReport report,
  required TestController tester,
}) async {
  final regEx = tester.resolveVariable(this.regEx).toString();
  final variableName =
      tester.resolveVariable(this.variableName) ?? '_testableId';

  final name = "$id('$regEx', '$variableName')";
  log(
    name,
    tester: tester,
  );

  TestStep? testStep;
  if (step != null) {
    testStep = TestStep.fromDynamic(step);
  }
  if (testStep == null) {
    throw Exception('for_each_testable: failing due to no sub-step');
  }

  final regExp = RegExp(regEx);
  final testables = find.byType(Testable).evaluate();
  for (var testable in testables) {
    if (cancelToken.cancelled == true) {
      throw Exception('[CANCELLED]: the step has been cancelled.');
    }
    final key = testable.widget.key;
    if (key is ValueKey) {
      final id = key.value.toString();
      if (id.isNotEmpty == true && regExp.hasMatch(id)) {
        log(
          'for_each_testable: testableId: [$id]',
          tester: tester,
        );
        tester.setTestVariable(
          value: id,
          variableName: variableName,
        );
        await tester.executeStep(
          cancelToken: cancelToken,
          report: report,
          step: testStep,
          subStep: true,
        );
      }
    }
  }
}