Closed saravanakumar-nc closed 3 months ago
Same here. in C# extent.attachReporter take 1 arg only, not 2. so merging does not seem to be implemented in 5.0.2,
Can you try with this?
https://extentreports.com/docs/versions/5/net/index.html#combine-multiple-reports
A little bit more context here: https://github.com/extent-framework/extentreports-java/issues/184
AttachReporter take 1 argument .
extent.AttachReporter(json, spark); => not available
Call this method twice, for each reporter?
The above should allow you to add multiple reporters. And on second thought, I will have to look into this behavior of adding all reporters in a single call in detail.
oh maybe i m wrong. will try to call this twice. I just start to experiment the merging capabilities. i will try next week.
Great library. thank you for your quick support.
@anshooarora , Thank you for the quick response. In Java, this is what they do to merge multiple spark html reports into one html file - using createDomainFromJsonArchive method. Ref from stackoverflow: https://stackoverflow.com/a/76234261
//Creating individual Report Number 1
ExtentSparkReporter spark = new ExtentSparkReporter("Report1.html");
JsonFormatter json = new JsonFormatter(opFolder + "/Report1.json");
ExtentReports extent = new ExtentReports();
extent.createTest("test1").assignCategory("cat").pass("Step 1 from test 1")
.fail("step 2 from test 1");
extent.attachReporter(json, spark);
extent.flush();
//Creating individual Report Number 2
ExtentSparkReporter spark2 = new ExtentSparkReporter("Report2.html");
JsonFormatter json2 = new JsonFormatter(opFolder + "/Report2.json");
ExtentReports extent2 = new ExtentReports();
extent2.createTest("test2").assignCategory("cat").pass("Step 1 from test 2")
.fail("step 2 from test 2");
extent2.attachReporter(json2, spark2);
extent2.flush();
ExtentSparkReporter mergedSpark = new ExtentSparkReporter("spark.html");
ExtentReports extentMerged = new ExtentReports();
//Replace below logic to get all the .json files generated by extent in opFolder
File jsonOPDirectory = new File("ExtentJson");
if (jsonOPDirectory.exists()) {
Arrays.stream(jsonOPDirectory.listFiles()).forEach(jsonFile -> {
try {
extentMerged.createDomainFromJsonArchive(jsonFile.getPath());
} catch (IOException e) {
e.printStackTrace();
}
});
}
extentMerged.attachReporter(mergedSpark);
extentMerged.flush();
In C#, I don't see any json files generated with ExtentSparkReporter. And I do not find the method createDomainFromJsonArchive at ExtentReports class.
Anyway, I tried to use AttachReporter but it does not help. I do not think this is the right way to merge the reports.
string outputDirectory = "Desktop\\testresults";
var mergedReport = new ExtentReports();
var mergeSpark = new ExtentSparkReporter(outputDirectory + @"\merge\MergedReport.html");
mergeSpark.LoadJSONConfig(outputDirectory + @"\merge\spark-config.json");
// These extent spark reports is already generated. I am just trying to attach these with mergeSpark
var spark1 = new ExtentSparkReporter(outputDirectory @ + "\testsuite_1\extent-report.html");
var spark2 = new ExtentSparkReporter(outputDirectory @ + "\testsuite_2\extent-report.html");
mergedReport.AttachReporter(mergeSpark);
mergedReport.AttachReporter(spark1);
mergedReport.AttachReporter(spark2);
mergedReport.Flush();
It did not throw any error and it did not generate MergedReport.html. It did generate extent folder.
We have multiple test-pipeline and each will generate individual spark report html file. I am looking for a way to merge all the files and have one extent html file - just like how they are doing it in java.
Please let me know if there are any alteratives with C# or am I missing something?
See here: https://github.com/extent-framework/extentreports-csharp/blob/master/ExtentReports/Core/ExtentReports.cs#L144. The method is available. What version are you using?
My bad, its there. It works absolutely fine.
This is how I have implemented incase if any one needed it.
// Ensure your existing test suites are configured to generate both JSON and HTML reports var extent = new ExtentReports(); var htmlReporter = new ExtentSparkReporter("extent-report.html"); var jsonReporter = new ExtentJsonReporter("extent-report.json"); extent.AttachReporter(jsonReporter, htmlReporter);
// Run your tests and log the results
// Finally make sure to flush it extent.Flush();
Once we have all the test results, we can generate the merged report. Lets say we have 3 test results at "testresults" directory as below... TestSuite1 - this will have extent-report.html, extent-report.json TestSuite2 - this will have extent-report.html, extent-report.json TestSuite3 - this will have extent-report.html, extent-report.json
string outputDirectory = "\testresults"; string[] jsonFiles = Directory.GetFiles(outputDirectory, "*.json", SearchOption.AllDirectories);
var extent = new ExtentReports();
foreach (var jsonFile in jsonFiles) { extent.CreateDomainFromJsonArchive(jsonFile); }
var mergeSparkReporter = new ExtentSparkReporter(outputDirectory + @"\Final\merged-extent-report.html"); mergeSparkReporter.LoadJSONConfig("spark-config.json"); // if you have any config file
extent.AttachReporter(mergeSparkReporter); extent.Flush();
Thank you for your help. I am closing this.
Hi, I noticed a thread, but for Java where there is a way to merge multiple Spark reports into one html report. Is there a way to Merge the Spark html reports generated in CSharp?
In Java, looks like they are using Json file to merge the reports. Java ref. thread - https://github.com/extent-framework/extentreports-java/issues/331