Selenium Webdriver Appium Complete TutorialSelenium Webdriver Appium Complete Tutorial
Automation Testing
  • Tools
    • Selenium
      • Selenium Java Tutorial
      • Selenium C# Tutorial
    • Appium
      • Appium Java Tutorial
      • Appium C#Tutorial
    • Katalon
  • Trainings
  • TestNG
  • Reports
    • Extent Reports
      • Extent Reports – Java
      • Extent Reports – Java -Version3
      • Extent Reports – C#
    • Vigo Reports
    • AT Excel Report
  • Excel
    • Apache POI – Java
    • Excel With C#
  • Interview Questions
    • Selenium Interview Questions
    • Java Interview Questions
    • C# Interview Questions
  • Demo Site
  • Practice Site
  • More…
    • AutoIt
    • Sikuli
    • Robot Class
    • File Upload
    • ScreenShot
      • AShot
      • ShutterBug
  • About
February 25, 2017

Extent Report With Multiple Classes





Extent Report with Multiple classes will discuss about how to create a single report when you have multiple classes. Usually people will face issue that they will get the report with single class as all the extent reports related classes will be in the same class but when they have multiple classes then they might not get the single report for all the methods which are there in the different classes.

To overcome this issue, we need to create a separate class to declare the extent reports related classes and need to extend that class to access the object of those classes in each class where we need to generate the report for the test methods.

To show this, here we will create a class(i.e. BaseTest) to declare the extent reports related classes and will create 2 more classes(i.e. Functionality1 and Functionality2) to access these objects and will create a single report from these two classes.

The most important thing here is, once you create an object to the extent report classes we need to access the same object in different classes for this we have declare these variables as static then all the instances share the same copy of that variable. And a class variable can be accessed directly with the class, without the need to create an instance.

Below is the BaseTest class where we can declare the classes which are required to generate the extent reports and will configure the basic information for the report how it should generate. As we know that extent reports will use TestNG to generate the reports. Basic configuration is single time activity so we will put that code in @BeforeSuite and @AfterSuite annotations. And will run the code using testng.xml file as we need to run multiple classes at a time.

import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class BaseTest
{
    public static ExtentHtmlReporter htmlReporter;
    public static ExtentReports extent;
    public static ExtentTest test;
    
    @BeforeSuite
    public void setUp()
    {
        htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
        extent = new ExtentReports();
        extent.attachReporter(htmlReporter);
        
        extent.setSystemInfo("OS", "Mac Sierra");
        extent.setSystemInfo("Host Name", "Krishna");
        extent.setSystemInfo("Environment", "QA");
        extent.setSystemInfo("User Name", "Krishna Sakinala");
        
        htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
        htmlReporter.config().setReportName("My Own 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.ORANGE));
            test.skip(result.getThrowable());
        }
    }
    
    @AfterSuite
    public void tearDown()
    {
        extent.flush();
    }
}




Below is the class1 (i.e. Functionality1) which will have actual test cases/scripts and need to generate the report for the status of the test methods under this class. So, we will extend the BaseTest to this class to access the extent report related classes.

import org.testng.Assert;
import org.testng.annotations.Test;

public class Functionality1 extends BaseTest
{
    @Test
    public void functionality1Test1()
    {
        test = extent.createTest("functionality1Test1");
        Assert.assertTrue(1 > 0);
    }
    
    @Test
    public void functionality1Test2()
    {
        test = extent.createTest("functionality1Test2");
        Assert.assertEquals("Krishna", "Sakinala");
    }
    
    @Test
    public void functionality1Test3()
    {
        test = extent.createTest("functionality1Test3");
        Assert.assertNotEquals("Krishna", "Krishna");
    }
}

Below is the class2 (i.e. Functionality2) which will have actual test cases/scripts and need to generate the report for the status of the test methods under this class. So, we will extend the BaseTest to this class to access the extent report related classes.

import org.testng.Assert;
import org.testng.annotations.Test;

public class Functionality2 extends BaseTest
{
    @Test
    public void functionality2Test1()
    {
        test = extent.createTest("functionality2Test1");
        Assert.assertTrue(1 > 0);
    }
    
    @Test
    public void functionality2Test2()
    {
        test = extent.createTest("functionality2Test2");
        Assert.assertEquals("Krishna", "Sakinala");
    }
    
    @Test
    public void functionality2Test3()
    {
        test = extent.createTest("functionality2Test3");
        Assert.assertNotEquals("Krishna", "Krishna");
    }
}




Now we will run the both classes using testng.xml file and will get the consolidated report for both the classes. Can find the same report below:

Report from Multiple Classes

This way we can generate the single report from multiple classes.

Please watch the YouTube video of this blog for better understanding.



Share this post: on Twitter on Facebook

Capture FullPage Screenshot in Extent Reports – Java Generate Excel Report in Selenium using TestNG

Related Posts

Capture FullPage Screenshot in Extent Reports – Java

Extent Reports-Java-Version3

Capture FullPage Screenshot in Extent Reports – Java

CAPTURE SCREENSHOTS IN EXTENT REPORTS JAVA

Extent Reports-Java-Version3

Capture Screenshot in Extent Reports – Java – Version3

EXTENT REPORTS LOG GENERATION JAVA

Extent Reports-Java-Version3

Extent Reports Log Generation – Java – Version3

GENERATING EXTENT REPORTS JAVA-V3

Extent Reports-Java-Version3

Generating Extent Reports – Java – Version3

EXTENT REPORTS INTRODUCTION JAVA

Extent Reports-Java-Version3

Extent Reports Introduction – Java – Version3

Newsletter

Recent Posts

  • TAKING WEB ELEMENT SCREENSHOT IN SELENIUMHow to Capture WebElement Screenshot in Selenium Webdriver using selenium 4
    December 15, 2019
  • How To SWAP Two Numbers in Java Without using Temp VariableHow to SWAP Two Numbers in Java Without Temp variable or Without Third variable
    December 8, 2019
  • How to Swap Two Numbers in Java with Temp VariableHow to SWAP Two Numbers in Java using Temp Variable
    December 1, 2019
  • How to Read Properties file in JavaHow to Read Data From Properties File in Java
    November 27, 2019
  • Compare two arrays in java with out inbuilt functionsHow to Compare Two Arrays in Java without built-in functions
    November 16, 2019
© Selenium Webdriver Appium Complete Tutorial 2025