captureArtifact method
Implementation
@override
Future<TestArtifact> captureArtifact(ArtifactRequest request) {
return RunnerBenchmark.future('session', 'captureArtifact', () {
_ensureOpen();
return queue.run(() async {
resolver.invalidateResolvedFinders();
if (!policy.permissions.captureArtifacts || !capabilities.screenshots) {
throw const TestExecutionError(
code: TestExecutionErrorCode.permissionDenied,
message: 'Not permitted to capture artifacts.',
);
}
if (request.kind != 'screenshot') {
throw TestExecutionError(
code: TestExecutionErrorCode.unsupportedAction,
message: 'Unsupported artifact kind "${request.kind}".',
);
}
final image = ExtendedStepHandlers.captureScreenshotImage(tester);
try {
final byteData = await LiveAsyncCallSupport.runUntracked(
() => image.toByteData(format: ui.ImageByteFormat.png),
runnerOverride: tester.runAsync,
);
if (byteData == null) {
throw const TestExecutionError(
code: TestExecutionErrorCode.internalError,
message: 'Failed to encode screenshot as PNG.',
);
}
final bytes = byteData.buffer.asUint8List();
final id = 'art_${sessionId}_${_actionSeq++}';
_artifactStore[id] = bytes;
return TestArtifact(
artifactId: id,
kind: 'screenshot',
path: 'memory:$id',
mimeType: 'image/png',
byteLength: bytes.length,
);
} finally {
image.dispose();
}
});
});
}