Class CucumberJsonWriter

java.lang.Object
io.karatelabs.output.CucumberJsonWriter

public final class CucumberJsonWriter extends Object
Generates Cucumber JSON reports compatible with third-party tools (Allure, ReportPortal, etc.).

Output follows the standard Cucumber JSON schema:

 [
   {
     "id": "feature-id",
     "uri": "path/to/feature.feature",
     "name": "Feature Name",
     "keyword": "Feature",
     "elements": [
       {
         "id": "feature-id;scenario-id",
         "name": "Scenario Name",
         "keyword": "Scenario",
         "type": "scenario",
         "steps": [
           {
             "keyword": "Given ",
             "name": "step text",
             "result": { "status": "passed", "duration": 12345678 }
           }
         ]
       }
     ]
   }
 ]
 
  • Method Details

    • serializeFeature

      public static String serializeFeature(FeatureResult result)
      Serialize a feature result to its JSON text.

      Separated from the file write so a listener can do this synchronously, while the result is still whole. The suite releases nested karate.call() trees once a feature's listeners have returned, and this output flattens called features' steps into its own — so serializing on a background thread would silently drop them.

    • fileNameFor

      public static String fileNameFor(FeatureResult result)
      File name this feature's output is written under.
    • writeSerialized

      public static void writeSerialized(String fileName, String content, Path outputDir)
      Write pre-serialized content. Safe after the source result has been released.
    • writeFeature

      public static void writeFeature(FeatureResult result, Path outputDir)
    • featureToJson

      public static String featureToJson(FeatureResult result)
      Convert a single feature result to Cucumber JSON string.

      Returns a JSON array containing a single feature object.

      Parameters:
      result - the feature result
      Returns:
      JSON string