Class JsonLinesEventWriter

java.lang.Object
io.karatelabs.core.JsonLinesEventWriter
All Implemented Interfaces:
RunListener, Closeable, AutoCloseable

public class JsonLinesEventWriter extends Object implements RunListener, Closeable
A RunListener that streams events to a JSON Lines (.jsonl) file.

This writer outputs events in the standard envelope format:

 {"type":"SUITE_ENTER","timeStamp":1703500000000,"threadId":null,"data":{...}}
 {"type":"FEATURE_ENTER","timeStamp":1703500000010,"threadId":"worker-1","data":{...}}
 {"type":"SCENARIO_ENTER","timeStamp":1703500000020,"threadId":"worker-1","data":{...}}
 {"type":"SCENARIO_EXIT","timeStamp":1703500000100,"threadId":"worker-1","data":{...}}
 {"type":"FEATURE_EXIT","timeStamp":1703500000200,"threadId":"worker-1","data":{...}}
 {"type":"SUITE_EXIT","timeStamp":1703500010000,"threadId":null,"data":{...}}
 

Use cases:

  • Real-time test dashboards - stream lightweight events as tests run
  • CI/CD integration - parse events for build status, notifications
  • Report aggregation - combine JSONL from multiple runs/machines
  • IDE integration - SCENARIO_ENTER/EXIT events for test runners
  • Field Details

  • Constructor Details

    • JsonLinesEventWriter

      public JsonLinesEventWriter(Path outputDir, String env, int threadCount)
      Create a new JSON Lines event writer.
      Parameters:
      outputDir - the directory to write the file
      env - the karate environment (may be null)
      threadCount - the number of parallel threads
  • Method Details

    • init

      public void init() throws IOException
      Initialize the writer. Must be called before events are fired.
      Throws:
      IOException
    • onEvent

      public boolean onEvent(RunEvent event)
      Description copied from interface: RunListener
      Called for all runtime events.
      Specified by:
      onEvent in interface RunListener
      Parameters:
      event - the event containing type, runtime objects, and results
      Returns:
      true to continue execution, false to skip (only meaningful for *_ENTER events)
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getJsonlPath

      public Path getJsonlPath()
      Get the path to the JSON Lines file.