Package io.karatelabs.output
Class HtmlReportWriter
java.lang.Object
io.karatelabs.output.HtmlReportWriter
Generates HTML reports with inlined JSON data and Alpine.js client-side rendering.
This implementation uses a single-file HTML architecture where:
- JSON data is inlined in a
<script type="application/json">tag - Alpine.js renders the content client-side
- No server-side template rendering is required
Output structure:
target/karate-reports/
├── index.html (redirects to karate-summary.html)
├── karate-summary.html (summary page with tag filtering)
├── karate-timeline.html (parallel-execution Gantt)
├── feature-html/
│ └── {feature.path}.html (per-feature reports, dot-based naming)
├── karate-json/karate-events.jsonl (streamed during execution, opt-in)
└── res/
├── bootstrap.min.css
├── alpine.min.js
└── karate-report.css
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopyStaticResources(Path resDir) Copy static resources (CSS, JS, images) to the res directory.static voidexternalizeEmbeds(FeatureResult result, Path outputDir) Externalize a feature result's inline-bytes embeds to<outputDir>/embeds/and set each part'sfileName, so EVERY downstream serializer — the JSONL event stream and the HTML data JSON — references the file rather than inlining base64 (large screenshots stay on disk, the report still works off a folder /file://).prepareFeatureData(FeatureResult result, Path outputDir) Extract everything the feature page needs from a liveFeatureResult.static voidrenderFeatureHtml(Map<String, Object> featureData, Path outputDir, Map<String, ReportAssets> reportAssets) Template + IO only.static voidReset the embed file sequence.static voidwrite(SuiteResult result, Path outputDir, String env) Generate HTML reports from a SuiteResult.static voidwriteFeatureHtml(FeatureResult result, Path outputDir) Write a single feature HTML report.static voidwriteFeatureHtml(FeatureResult result, Path outputDir, Map<String, ReportAssets> reportAssets) static voidwriteSummaryPages(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env) Write summary pages (summary, index) from feature maps.static voidwriteSummaryPages(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env, Map<String, ReportAssets> reportAssets) static voidwriteSummaryPages(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env, Map<String, ReportAssets> reportAssets, List<Map<String, Object>> summaryCards) static voidwriteTimelineHtml(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env, int threadCount) Write the timeline HTML page showing scenario execution across threads.static voidwriteTimelineHtml(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env, int threadCount, Map<String, ReportAssets> reportAssets)
-
Method Details
-
resetEmbedCounter
public static void resetEmbedCounter()Reset the embed file sequence. Called at suite start so embed file names (e.g.001_screenshot.png) restart from 1 for each run instead of accumulating across runs in the same JVM. -
write
Generate HTML reports from a SuiteResult. This is the backward-compatible entry point for direct invocation.- Parameters:
result- the suite result to renderoutputDir- the directory to write reportsenv- the karate environment (may be null)
-
writeFeatureHtml
Write a single feature HTML report. Used byHtmlReportListenerfor async feature HTML generation.- Parameters:
result- the feature result to renderoutputDir- the root output directory (features/ subdirectory will be used)- Throws:
IOException
-
writeFeatureHtml
public static void writeFeatureHtml(FeatureResult result, Path outputDir, Map<String, ReportAssets> reportAssets) throws IOException- Throws:
IOException
-
prepareFeatureData
public static Map<String,Object> prepareFeatureData(FeatureResult result, Path outputDir) throws IOException Extract everything the feature page needs from a liveFeatureResult.Split out from the render so a caller can do this synchronously, while the feature result is still whole, and defer only templating and IO. That ordering is what lets a suite release the nested
karate.call()result trees as soon as a feature completes: everything the report needs has already been copied out. Do the extraction late — on a background thread, say — and the report silently loses its nested step detail.- Throws:
IOException
-
renderFeatureHtml
public static void renderFeatureHtml(Map<String, Object> featureData, Path outputDir, Map<String, throws IOExceptionReportAssets> reportAssets) Template + IO only. Safe to run after the sourceFeatureResulthas been released.- Throws:
IOException
-
externalizeEmbeds
Externalize a feature result's inline-bytes embeds to<outputDir>/embeds/and set each part'sfileName, so EVERY downstream serializer — the JSONL event stream and the HTML data JSON — references the file rather than inlining base64 (large screenshots stay on disk, the report still works off a folder /file://). Called from theFEATURE_EXITseam (Suite.fireEvent) before any listener serializes the result; idempotent (a part with a fileName is skipped), so the HTML writer's later pass numbers each embed exactly once. Best-effort — a write failure never breaks the run. JSON evidence stays inline (seewriteEmbedFile(io.karatelabs.core.StepResult.Embed, java.nio.file.Path)). -
writeSummaryPages
public static void writeSummaryPages(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env) throws IOExceptionWrite summary pages (summary, index) from feature maps. Used byHtmlReportListenerat suite end.- Parameters:
features- the collected feature maps (from FeatureResult.toJson())result- the suite resultoutputDir- the root output directoryenv- the karate environment (may be null)- Throws:
IOException
-
writeSummaryPages
public static void writeSummaryPages(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env, Map<String, throws IOExceptionReportAssets> reportAssets) - Throws:
IOException
-
writeSummaryPages
public static void writeSummaryPages(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env, Map<String, throws IOExceptionReportAssets> reportAssets, List<Map<String, Object>> summaryCards) - Throws:
IOException
-
copyStaticResources
Copy static resources (CSS, JS, images) to the res directory. Made public for use byHtmlReportListener.- Parameters:
resDir- the res directory to copy resources to- Throws:
IOException
-
writeTimelineHtml
public static void writeTimelineHtml(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env, int threadCount) throws IOExceptionWrite the timeline HTML page showing scenario execution across threads. Used byHtmlReportListenerat suite end.- Parameters:
features- the collected feature maps (from FeatureResult.toMap())result- the suite resultoutputDir- the root output directoryenv- the karate environment (may be null)threadCount- the number of threads used for parallel execution- Throws:
IOException
-
writeTimelineHtml
public static void writeTimelineHtml(List<Map<String, Object>> features, SuiteResult result, Path outputDir, String env, int threadCount, Map<String, throws IOExceptionReportAssets> reportAssets) - Throws:
IOException
-