captureHostStepScreenshot function
Future<void>
captureHostStepScreenshot({
- required WidgetTester tester,
- required EnsembleTestContext context,
- required AssertionEngine assertions,
- required TestStep step,
- required int stepIndex,
- bool atCurrentFrame = false,
- ObservationDetailLevel observationDetail = ObservationDetailLevel.standard,
Captures one report frame for a host test step.
Failures here must not change the test result — the HTML gallery is diagnostic, not an assertion.
Implementation
Future<void> captureHostStepScreenshot({
required WidgetTester tester,
required EnsembleTestContext context,
required AssertionEngine assertions,
NavigationTestService? navigation,
required TestStep step,
required int stepIndex,
bool atCurrentFrame = false,
ObservationDetailLevel observationDetail = ObservationDetailLevel.standard,
}) async {
if (!context.config.screenshots.shouldCaptureStep(step.type)) return;
try {
if (!atCurrentFrame) {
// Live API callbacks run in real async time, but widget animations use
// the test binding's fake frame clock. Advance it through short content
// transitions before rasterizing (for example LoadingContainer's
// AnimatedSwitcher), otherwise Observer can see loaded children while
// the screenshot still captures them at zero opacity.
await tester.pump(kScreenshotTransitionSettleDuration);
// One more frame so a newly mounted theme (EnsembleApp after login)
// can apply preloaded fallback fonts before we rasterize.
await tester.pump();
}
// Capture is synchronous; do not wrap it in runAsync.
final visual = captureStepVisualSnapshot(
tester: tester,
assertions: assertions,
navigation: navigation,
observationDetail: observationDetail,
);
final image = visual.image;
final observerSnapshot = visual.observerSnapshot;
final device = hostScreenshotDevice(context);
final highlight = _hostStepHighlight(
tester: tester,
assertions: assertions,
step: step,
image: image,
device: device,
observation: observerSnapshot?.observation,
);
writeStepScreenshotArtifacts(
tester: tester,
context: context,
step: step,
stepIndex: stepIndex,
image: image,
device: device,
highlight: highlight,
observerSnapshot: observerSnapshot,
);
} catch (error) {
if (!isHostScreenshotDiagnostic(error) &&
!isHostScreenshotCaptureFailure(error)) {
rethrow;
}
context.runtime.consoleLogs.add(
context.runtime.formatConsoleLine(
'[Screenshot] Step $stepIndex capture skipped: $error',
),
);
// Do not call tester.takeException() — that would drain unrelated
// application FlutterErrors recorded for the host attempt.
}
}