runSteps static method
Future<List<PlaybookStepResult> >
runSteps(
- PlaybookActor actor,
- List<
PlaybookStep> steps, - PlaybookStepContext context, {
- bool skipAll = false,
Runs steps in order with actor, stopping at the first failure.
Steps after a failure, or every step when skipAll, are reported as
skipped.
Implementation
static Future<List<PlaybookStepResult>> runSteps(
PlaybookActor actor,
List<PlaybookStep> steps,
PlaybookStepContext context, {
bool skipAll = false,
}) async {
final PlaybookSession session = actor.session;
final PlaybookClock clock = session.clock;
final List<PlaybookStepResult> results = [];
final int total = steps.length;
bool halted = skipAll;
for (int i = 0; i < total; i++) {
final PlaybookStep step = steps[i];
final int index = i + 1;
final bool group = step is PlaybookGroupStep;
if (halted || session.stopRequested) {
final PlaybookStepResult skipped = PlaybookStepResult(
title: step.title,
status: PlaybookStepStatus.skipped,
);
results.add(skipped);
_emitStep(context.emit, context, index, total, skipped, group: group);
continue;
}
context.emit?.call({
'event': 'begin',
'name': context.playbook,
'index': index,
'total': total,
'title': step.title,
'depth': context.depth,
'group': group,
});
final PlaybookOverlay? overlay = session.overlay;
if (overlay != null) {
overlay.text.value = '${context.caption}$index/$total ยท ${step.title}';
overlay.bringToFront();
}
final Duration start = clock.elapsed;
PlaybookStepResult result;
try {
if (step is PlaybookGroupStep) {
final List<PlaybookStepResult> children = await step.group(
actor,
context.nested(index: index, total: total, title: step.title),
);
result = _groupResult(step.title, children, clock.elapsed - start);
} else {
await step.action(actor);
await actor.settle();
result = PlaybookStepResult(
title: step.title,
status: PlaybookStepStatus.passed,
elapsed: clock.elapsed - start,
);
}
} on PlaybookStopped {
result = PlaybookStepResult(
title: step.title,
status: PlaybookStepStatus.skipped,
elapsed: clock.elapsed - start,
error: 'Stopped',
);
} on PlaybookFailure catch (e) {
result = PlaybookStepResult(
title: step.title,
status: PlaybookStepStatus.failed,
elapsed: clock.elapsed - start,
error: e.message,
visibleText: e.visibleText,
);
} catch (e) {
result = PlaybookStepResult(
title: step.title,
status: PlaybookStepStatus.failed,
elapsed: clock.elapsed - start,
error: _describe(e),
visibleText: PlaybookTree(
WidgetsBinding.instance.rootElement,
).visibleText(),
);
}
results.add(result);
_emitStep(context.emit, context, index, total, result, group: group);
if (result.status == PlaybookStepStatus.failed) {
halted = true;
} else if (index < total) {
try {
await actor.wait(actor.speed.betweenSteps);
} on PlaybookStopped {
// The next step is reported as skipped.
}
}
}
return results;
}