Class HtmlReportWriter

java.lang.Object
io.karatelabs.output.HtmlReportWriter

public final class HtmlReportWriter extends Object
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 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

      public static void write(SuiteResult result, Path outputDir, String env)
      Generate HTML reports from a SuiteResult. This is the backward-compatible entry point for direct invocation.
      Parameters:
      result - the suite result to render
      outputDir - the directory to write reports
      env - the karate environment (may be null)
    • writeFeatureHtml

      public static void writeFeatureHtml(FeatureResult result, Path outputDir) throws IOException
      Write a single feature HTML report. Used by HtmlReportListener for async feature HTML generation.
      Parameters:
      result - the feature result to render
      outputDir - 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
    • writeSummaryPages

      public static void writeSummaryPages(List<Map<String,Object>> features, SuiteResult result, Path outputDir, String env) throws IOException
      Write summary pages (summary, index) from feature maps. Used by HtmlReportListener at suite end.
      Parameters:
      features - the collected feature maps (from FeatureResult.toJson())
      result - the suite result
      outputDir - the root output directory
      env - 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,ReportAssets> reportAssets) throws IOException
      Throws:
      IOException
    • writeSummaryPages

      public static void writeSummaryPages(List<Map<String,Object>> features, SuiteResult result, Path outputDir, String env, Map<String,ReportAssets> reportAssets, List<Map<String,Object>> summaryCards) throws IOException
      Throws:
      IOException
    • copyStaticResources

      public static void copyStaticResources(Path resDir) throws IOException
      Copy static resources (CSS, JS, images) to the res directory. Made public for use by HtmlReportListener.
      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 IOException
      Write the timeline HTML page showing scenario execution across threads. Used by HtmlReportListener at suite end.
      Parameters:
      features - the collected feature maps (from FeatureResult.toMap())
      result - the suite result
      outputDir - the root output directory
      env - 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,ReportAssets> reportAssets) throws IOException
      Throws:
      IOException