BaseTest.java:
private static ReportService reportService; // Calling report service interface
@BeforeSuite:
reportService = new ExtentReportService(getConfig()); // New instance of ExtentReportService.
@BeforeMethod:
reportService.startTest(testname); // Starting the test and passing the name and description of the test.
@AfterMethod:
reportService.endTest(); // Ending the test
@AfterSuite:
reportService.close(); // Closing the test
**ExtentReportService.java:** // Contains different extent API methods. (These are designed to be generic.)
protected static ExtentReports extent; // static instance of ExtentReports
protected static ExtentTest test; //static instance of ExtentTTest
@Override // StartTest method
startTest(Method method) {
testMetaData = getTestMetaData(method);
test=extent.startTest(testMetaData.getId(),testMetaData.getSummary());
}
@Override //End test method
endTest() {
extent.endTest(test);
extent.flush();
}
- The above is my selenium code.
- When I am executing my suite file with parallel="methods" and thread count="3", I am getting the following error: "com.relevantcodes.extentreports.ExtentTestInterruptedException: Close was called before test could end safely using EndTest.".
- While debugging, I found that even before all endTest() in AfterMehtod were executed, AfterSuite was being called.
- I tried different variations such that the code works, such as, removing static, calling endTest() in the test itself rather than after method, removing close() call from AfterSuite and many other variations. But still getting the same error.
I tried all the possible solutions given on the internet, but to no use.
- Attaching a hierarchy file for the ExtentReport used in my project
- I also the following solution given in StackOverflow: Extent report :com.relevantcodes.extentreports.ExtentTestInterruptedException: Close was called before test could end safely using EndTest
- Unsynchronized output
- XMF file for parallel test.