jeudi 8 juin 2017

Not able to generate Extent Reports when classes running parallel with TestNG

When classes running parallel with TestNG we are not getting Extent Report but TestNG report is getting updated. Please find the below sample code. If we are running only one class (TestClass1.java) then Extent Report will generate.

Selenium version 3.4.0

Extent Report Version : 3.0.6

ExtentReportBase.java

ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;


@BeforeTest
public void setUp()
{
    //where we need to generate the report
    htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir")+"/test-output/MyReport.html");
    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);

    // Set our document title, theme etc..
    htmlReporter.config().setDocumentTitle("Suraj Test Report");
    htmlReporter.config().setReportName("Test Report");
    htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
    htmlReporter.config().setTheme(Theme.DARK); 

}

@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.YELLOW));
    }

}

@AfterSuite
public void tearDown()
{
    extent.flush();
}

TestClass1.java

@Test
public void functionality1Test1()
{
    test = extent.createTest("functionality1Test1");
    Assert.assertTrue(1 > 0);
}

@Test
public void functionality1Test2()
{
    test = extent.createTest("functionality1Test2");
    Assert.assertEquals("Google", "goo");
}

@Test
public void functionality1Test3()
{
    test = extent.createTest("functionality1Test3");
    Assert.assertNotEquals("Google", "Google");
}    

TestClass2.java

@Test
public void functionality2Test1()
{
    test = extent.createTest("functionality2Test1");
    Assert.assertTrue(1 > 0);
}

@Test
public void functionality2Test2()
{
    test = extent.createTest("functionality2Test2");
    Assert.assertEquals("Google", "goo");
}

@Test
public void functionality2Test3()
{
    test = extent.createTest("functionality2Test3");
    Assert.assertNotEquals("Google", "Google");
}

Aucun commentaire:

Enregistrer un commentaire