Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karate 1.5.0.RC4: cucumber.json Report Not Generated, Only .feature-json.txt Files Created #2582

Closed
medJarray opened this issue Jul 18, 2024 · 1 comment
Labels

Comments

@medJarray
Copy link

medJarray commented Jul 18, 2024

Hello, I encountered an issue after upgrading from Karate version 0.9.6 to version 1.5.0.RC4. The problem is that the cucumber.json report is not generated; instead, a .feature-json.txt file is generated.

I am using the following for my Karate project for automated tests:

  • Karate library 1.5.0.RC4
  • GraalVM 23.0.4
  • Java 21
  • Cucumber-reporting 5.8.2

Here is a code snippet:

public class DefaultCucumberRunner implements CucumberParallelRunner {

  @Override
  public Results run(CucumberRunnerParameters parameters) {
    var directoryPath = getClassPackagePath(parameters.getRunningClass());
    return Runner.path(getKarateFeaturePaths(directoryPath))
            .outputJunitXml(true)
            .outputCucumberJson(true)
            .tags("~@ignore")
            .parallel(parameters.getThreadCount());
  }

  private static List<String> getKarateFeaturePaths(String directoryPath) {
    var featureFiles = FileUtils.listFiles(
            new File(USER_DIRECTORY + FOLDER_SEPARATOR + directoryPath),
            new String[] {KARATE_FEATURE_EXTENSION},
            true
    );
    return featureFiles.stream()
            .map(File::getPath)
            .toList();
  }
}
public class ReportGenerator {
  private static final String CUCUMBER_HTML_REPORTS_PATH = "target/" + ReportBuilder.BASE_DIRECTORY;
  private final ReportHandler reportHandler;

  /** Clean up report directories. */
  public static void cleanUpReportDirectories(String karateOutputPath) throws IOException {
    FileUtils.deleteDirectory(new File(karateOutputPath));
    FileUtils.deleteDirectory(new File(CUCUMBER_HTML_REPORTS_PATH));
  }

  /** Generate a cucumber HTML report. */
  public void generateReport(String karateOutputPath, boolean isSuccessful) {

    var karateOutputFile = new File(karateOutputPath);

    if (!karateOutputFile.isDirectory()) {
      throw new IllegalArgumentException(
              "Karate report was not correctly created. This might be due to no Karate tests being launched.");
    }
    List<String> jsonPaths = FileUtils.listFiles(karateOutputFile, new String[]{"json"}, true)
            .stream()
            .map(File::getAbsolutePath)
            .toList();

    if (jsonPaths.isEmpty()) {
      throw new IllegalArgumentException("No Karate JSON report files found.");
    }

    var config = new Configuration(new File("target"), "my-project-automatedtest");
    config.setSortingMethod(SortingMethod.ALPHABETICAL);

    var reportBuilder = new ReportBuilder(jsonPaths, config);
    reportBuilder.generateReports();
    var reportDir = new File(config.getReportDirectory(), ReportBuilder.BASE_DIRECTORY);
    reportHandler.handleReport(reportDir, isSuccessful);
  }
}

The issue is that with this version of Karate, even when adding the outputCucumberJson(true) option, I do not find a .json report in the output directory target/karate-reports. I only see .feature-json.txt reports and .html files. Consequently, when generating the report, I encounter an error indicating that the JSON file is not found in the directory.
java.lang.IllegalArgumentException: No Karate JSON report files found.

@ptrthomas
Copy link
Member

sounds like a misconfiguration or wrong library still being used. happy to re-open if you follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants