Issue with Extent reports , when trying to a test method parallely using data provider

495 views
Skip to first unread message

naveen kumar

unread,
Mar 22, 2018, 5:03:23 AM3/22/18
to Selenium Users

I am trying to run a Test method multiple times parallely using the testng @Dataprovider(parallel=true), and getting logging issue with that . Below is the code am referring to

public class simpletest3 {
public ExtentReports rep=ExtentManager.getInstance();
public ExtentTest test;
public Keywords app;
public String testName;


@Test(dataProvider="dta")
public void mytest(String uname,String pwd){
    testName = "SamTest";
test = rep.createTest(testName);

System.out.println("Inside"+uname+pwd);
System.out.println(Thread.currentThread().getId());

test.info("Executing test Case with the data:: username ="+uname+" and the pwd = "+pwd);
}

 @DataProvider(parallel=false)
  public Object[][] dta(){

  return new Object[][] { { "testuser_1", "Test@123" }, 
        { "testuser_2", "Test@456" },
        { "testuser_3", "Test@458" },

        };          
  }


 @AfterMethod
 public void getResult(ITestResult result)
 {

 if(result.getStatus() == ITestResult.FAILURE)
 {
    test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Test case FAILED due to below issues:", ExtentColor.RED));
    test.fail(result.getThrowable());
}
else if(result.getStatus() == ITestResult.SUCCESS)
{
    test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" Test Case PASSED", ExtentColor.GREEN));
}
else
{
    test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" Test Case SKIPPED", ExtentColor.ORANGE));
    test.skip(result.getThrowable());
}

}

@AfterTest
 public void tearDown()
 {
 rep.flush();
 }`

And am trying to create a extent instance as below

public static ExtentReports getInstance(){

    Date d=new Date();
    String fileName=d.toString().replace(":", "_").replace(" ", "_")+".html";
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(Constants.REPORT_PATH+fileName);
    System.out.println(Constants.REPORT_PATH+fileName);
    //extent = new ExtentReports(Constants.REPORT_PATH+fileName, true, DisplayOrder.NEWEST_FIRST);
    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);
    return extent;
}

Here i am trying to run a test method three times using the dataprovider. Issue is when i run the test parallely using parallel=true, the extent logging i am doing is getting recorded weirdly .In the attached image we can see logging for run instance 1 and 2 are recorded in report of test method instance 1, and run instance 3 logging is done in report of test method 2 and nothing is logged in the report of test method 3 and some times all the logging is happening in one single report of test method ( 1 or 2 or 3 not sure),

And when parallel=false , logging is happening correctly in each instance report is showing its own logging .

Attached the screenshots for the same . Need help

false_report.JPG
True_report.JPG

⇜Krishnan Mahadevan⇝

unread,
Mar 22, 2018, 5:10:18 AM3/22/18
to seleniu...@googlegroups.com
Pls help keep this forum relevant by posting queries that are related to selenium/WebDriver. 

I would suggest that you post your query on the extent reports forum. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/bc372a2f-5312-49a3-a794-3963a1538238%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Magesh N

unread,
Mar 22, 2018, 5:59:20 AM3/22/18
to Selenium Users
Replace the following line in your code:
        public ExtentTest test; by
    public ThreadLocal<ExtentTest> test;

naveen kumar

unread,
Mar 22, 2018, 7:38:37 AM3/22/18
to Selenium Users
Thanks for the response Magesh. 

 if i use this
  public ThreadLocal<ExtentTest> test;

then i am getting the error at the line 

test=rep.createTest(testName);

and the error is "Type mismatch: cannot convert from ExtentTest to ThreadLocal<ExtentTest>" . And i am not cast this even 

Thanks
Naveen

M.R Chaudhary

unread,
Jul 1, 2018, 3:00:09 AM7/1/18
to Selenium Users
Can someone please solve this issue, i am also facing same error if using localthread, and without localthread report is not correct. What i noticed is with parallel execution default testng report is working perfectly but extent report have issue.
Reply all
Reply to author
Forward
0 new messages