I need to generate a file that consolidates all the results of each feature execution?
karate-dsl generates the test results in a JSON file for each of the executed feature files.
... so I created a utility that allows me to do it in Java.
I invite you to read the README https://github.com/jesusop/karate-cucumber-xray
The method reads all the json result files generated by karate and unifies them into a single cucumber.json file
You can aslo modify the paths of the files:
private static final String JSON_DIRECTORY = "/cucumber-html-reports";
private static final String CUCUMBER_JSON = "/cucumber.json";
private static void writeResultsToOneFile(JSONArray totalResults) throws IOException {
File currentDirectory = new File((new File(".")).getAbsolutePath());
String absolutePath = currentDirectory.getCanonicalPath();
File directory = new File(absolutePath + "/" + TARGET_DIRECTORY + JSON_DIRECTORY);
if (!directory.exists()) {
directory.mkdirs();
}
File cucumberJsonFile = new File(directory + CUCUMBER_JSON);
try (FileWriter fileWriter = new FileWriter(cucumberJsonFile)) {
fileWriter.write(totalResults.toJSONString());
}
logger.info("cucumber.json file has been created at: " + cucumberJsonFile.getAbsolutePath());
}
Note that upon completion of the tests, you will receive a message like this:
INFO: cucumber.json file has been created at: ...\karate-cucumber-xray\target\cucumber-html-reports\cucumber.json
Finally you can use the cucumber.json file and use it for example in the Jira Xray API.