3

I am getting below ExtentTestInterruptedException exception when I am running my test in multiple threads(Using TestNG to launch test in multiple threads):

com.relevantcodes.extentreports.ExtentTestInterruptedException: 
Close was called before test could end safely using EndTest.
    at com.relevantcodes.extentreports.Report.terminate(Report.java:425)
    at com.relevantcodes.extentreports.ExtentReports.close(ExtentReports.java:917)

Steps Followed

  1. I am starting my test in @BeforeTest method with extent report startTest method
  2. And ending my test with extent report endTest in @AfterMethod method
  3. My extent report close method is defined in @AfterSuite function.
  4. I removed close() method call from @AfterSuite but in that case result for few of the test cases appears as unknown.

Can someone please help me in resolving this query?

Hulk
  • 5,295
  • 1
  • 25
  • 49
  • Please share trial code. – Ishita Shah Dec 10 '18 at 09:40
  • import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; import java.io.File; public class ExtentReport { public static ExtentReports extent; public static ExtentTest test; public static void initExtentReport() { extent = new ExtentReports( System.getProperty("user.dir") +"/test-output" + File.separator + "API.html", true); extent.loadConfig(new File(System.getProperty("user.dir") + "/reportconfig.xml")); } } – Nikhil Indurkar Dec 10 '18 at 09:46
  • Include trial code in your question only. You need to share your code of AfterMethod and AfterSuite annotations. – Ishita Shah Dec 10 '18 at 09:48
  • @NikhilIndurkar I would recommend using version 4 API. Version 2 is no longer support and version 3 is also nearing end of support. Docs: http://extentreports.com/docs/versions/4/java/ – foursyth Dec 10 '18 at 15:28
  • @foursyth: I integrated with 4.05 version of aventstack extent report and I am not getting the same error message also but in this case the pass test case does not have any information i.e when I see the result the pass test case have no log information (Somehow I am not able to add attachment to this issue) – Nikhil Indurkar Dec 11 '18 at 12:17
  • It would be helpful to analyze if share your usage. There are a few changes in version 4 coming from 2. – foursyth Dec 11 '18 at 14:26
  • BeforeSuite public void setUp(){ htmlReporter = new ExtentHtmlReporter("./New.html"); extent = new ExtentReports(); extent.attachReporter(htmlReporter); } BeforeMethod(alwaysRun = true) public void beforeMethod(Method method) { test = extent.createTest( this.getClass().getSimpleName() + " :: " + method.getName()); } Test(dataProvider = "invoiceServiceData", groups = {"Sanity"}, threadPoolSize = 5, invocationCount = 10) test... AfterSuite public void tearDown(){ extent.flush(); } – Nikhil Indurkar Dec 11 '18 at 15:54

2 Answers2

1

This is related to extent report. I'm not sure how you write your @after method but only what i can guess is you use reports.endTest(test); in your code. This is in older version of extent report. Most probably your problem is with it. Here is an alternative with latest extent report solution since no extent report related code for your problem is available in here.

@AfterMethod
public synchronized void afterMethod(ITestResult result) {

    StringBuilder inputArgs = new StringBuilder();
    Object objects[] = result.getParameters();

    for(Object obj : objects){
        if(obj==null){
            inputArgs.append("  ");
        }else{
            inputArgs.append(obj.toString());
        }
        inputArgs.append(" , ");
    }

    if (result.getStatus() == ITestResult.FAILURE)
        test.get().fail(result.getThrowable()+ "Input Parameters : "+inputArgs.toString());
    else if (result.getStatus() == ITestResult.SKIP)
        test.get().skip(result.getThrowable() + "Input Parameters : "+inputArgs.toString());
    else
        test.get().pass( " Test Passed. Input parameters : " +inputArgs.toString());
    extent.flush();
}
Devdun
  • 667
  • 3
  • 10
0

When test fails, if it is not handled for the extend.endTest() you will face this issue. I have used the below ITestListener method to handle the test failure. Here the reason is captured and logged to the report and end the extent report logging.

public void onTestFailure(ITestResult t)
    {
        if(t.getStatus()==ITestResult.FAILURE) {
            String reason = t.getThrowable().toString();
            logger.log(LogStatus.FAIL, reason);
            extent.endTest(logger);
        }

    }
Siva
  • 13
  • 4