execute method

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

Function that is called when the step needs to execute.

Implementation

@override
Future<void> execute({
  required CancelToken cancelToken,
  required TestReport report,
  required TestController tester,
}) async {
  var value = tester.resolveVariable(this.value)?.toString();
  var maxIterations =
      JsonClass.parseInt(tester.resolveVariable(this.maxIterations), 100);
  var step = tester.resolveVariable(this.step);
  String counterVariableName =
      tester.resolveVariable(this.counterVariableName) ?? '_repeatNum';
  String variableName = tester.resolveVariable(this.variableName);

  var name =
      "$id('$variableName', '$value', '$maxIterations', '$counterVariableName')";
  log(
    name,
    tester: tester,
  );

  if (step == null) {
    throw Exception('repeat_until: failing due to no sub-step');
  }
  var testStep = TestStep.fromDynamic(step);
  tester.setTestVariable(
    value: 0,
    variableName: counterVariableName,
  );

  var actual = tester.resolveVariable('{{$variableName}}')?.toString();
  var iterations = 0;
  while (actual != value) {
    if (cancelToken.cancelled == true) {
      throw Exception('[CANCELLED]: the step has been cancelled.');
    }

    tester.setTestVariable(
      value: iterations,
      variableName: counterVariableName,
    );
    log(
      '$id: expected: [$value] -- actual: [$actual]',
      tester: tester,
    );
    if (maxIterations != null && iterations >= maxIterations) {
      throw Exception('$id: Max Iteration Count exceeded: $maxIterations');
    }

    await tester.executeStep(
      cancelToken: cancelToken,
      report: report,
      step: testStep,
      subStep: true,
    );

    actual = tester.resolveVariable('{{$counterVariableName}}')?.toString();

    iterations++;
  }
}