Reputation: 11
I have been using version 3 of Extent Reports for a while now. Everything works great but I want to use version 5 now since it's better and it has more functionality.
I know that in version 3 you can use htmlReporter.setAppendExisting(true);
to append test results to the report but how do you do it in v5?
I have looked through their documentation and I found this piece of code that is apparently supposed to work but I am getting a weird error.
This is the code:
spark = new ExtentSparkReporter (System.getProperty("user.dir") + "/reporti/TestExtentReport.html");
JsonFormatter json = new JsonFormatter("extent.json");
extent = new ExtentReports();
extent.createDomainFromJsonArchive("extent.json");
extent.attachReporter(spark,json);
logger = extent.createTest("Sklepanje");`
When I run this I am getting this error after the test is complete:
FAILED CONFIGURATION: @AfterTest iTriglavTesti.TestExtent.endReport
java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.String java.lang.Throwable.detailMessage accessible: module java.base does not "opens java.lang" to unnamed module @2cb4c3ab
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:153)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:96)
at com.google.gson.Gson.getAdapter(Gson.java:416)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:135)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:105)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:104)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:160)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:96)
at com.google.gson.Gson.getAdapter(Gson.java:416)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:135)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:105)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:104)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:160)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:96)
at com.google.gson.Gson.getAdapter(Gson.java:416)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
at com.google.gson.Gson.getAdapter(Gson.java:416)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(ReflectiveTypeAdapterFactory.java:135)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:105)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:104)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:160)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:96)
at com.google.gson.Gson.getAdapter(Gson.java:416)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:55)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.toJson(Gson.java:661)
at com.google.gson.Gson.toJson(Gson.java:640)
at com.google.gson.Gson.toJson(Gson.java:615)
at com.aventstack.extentreports.reporter.JsonFormatter.flush(JsonFormatter.java:57)
at com.aventstack.extentreports.reporter.JsonFormatter.access$000(JsonFormatter.java:17)
at com.aventstack.extentreports.reporter.JsonFormatter$1.onNext(JsonFormatter.java:37)
at com.aventstack.extentreports.reporter.JsonFormatter$1.onNext(JsonFormatter.java:30)
at io.reactivex.rxjava3.subjects.PublishSubject$PublishDisposable.onNext(PublishSubject.java:310)
at io.reactivex.rxjava3.subjects.PublishSubject.onNext(PublishSubject.java:226)
at com.aventstack.extentreports.ReactiveSubject.onFlush(ReactiveSubject.java:83)
at com.aventstack.extentreports.AbstractProcessor.onFlush(AbstractProcessor.java:85)
at com.aventstack.extentreports.ExtentReports.flush(ExtentReports.java:279)
at iTriglavTesti.TestExtent.endReport(TestExtent.java:433)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:361)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:644)
at org.testng.TestRunner.afterRun(TestRunner.java:914)
at org.testng.TestRunner.run(TestRunner.java:605)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:437)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:431)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:391)
at org.testng.SuiteRunner.run(SuiteRunner.java:330)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
at org.testng.TestNG.runSuites(TestNG.java:1099)
at org.testng.TestNG.run(TestNG.java:1067)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
I tried commenting out extent.createDomainFromJsonArchive("extent.json");
first and nothing changes I am still getting same error, but after I commented out JsonFormatter json = new JsonFormatter("extent.json");
the problem went away so I'm guessing there's something wrong here?
If anyone knows what's wrong or has any idea of what might be wrong please let me know.
Upvotes: 1
Views: 1719
Reputation: 75
I have encountered the same issue after upgrading from jdk11 to jdk17. After asking on extent-framework github, it was determined that it's a bug, currently in queue to be resolved. If that may be connected to your issue, you can follow it here.
Edited on 22/09/2023 : fix to that issue got introduced in ver. 5.1.1
Upvotes: 0
Reputation: 2053
In Extent 5 you can merge multiple HTML reports if you have the .json file generated by extent Report , we can use those to create a single html report with all merged results
#1 First we create a common output Folder for extent json files so that we can merge them all from a common folder #2 Them we generate two sample html Reports with there extent json files which are then written to common json folder
JsonFormatter json2 = new JsonFormatter(opFolder + "/Report2.json");
#3 Then we Create a Third extent Report , Take all the generated json files from folder and add their data into this and it will create a merged Report
extentMerged.createDomainFromJsonArchive(jsonFile.getPath());
Full Code
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.JsonFormatter;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
public class TestBase {
public static void main(String... a) throws IOException {
//Creating a Directory for Extent Json Output and create it if doesn't exist
File file = new File("ExtentJson");
if (!file.exists()) {
file.mkdir();
}
String opFolder = file.getPath();
//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();
}
}
Reference Combine Multiple Reports
Upvotes: 2