All IT Courses 50% Off
Selenium Tutorials

TestNG Report Generation in Selenium WebDriver

TestNG Reports:

TestNG Reports come into picture when we execute the test cases using TestNG Report generation is very important when you perform Manual Testing and Automation Testing. By going through the result, you can easily identify how many test cases are passed, how many are failed and how many test cases are skipped. By looking at the result report, you will know what the status of the project is. Selenium WebDriver is used only for automating web applications, but it won’t generate any reports. In this situation TestNG come into the picture once we execute test cases. TestNG will generate default HTML reports once we execute the test cases.

Using 3 Methods we can generate the TestNG Reports:

  1. emailable-report.html
  2. index.html
  3. Reporter Class

Method 1: emailable-report.html

Generally TestNG will generate default reports. You will get test-output folder when you execute testng.xml file and refresh the project. Right-click on emailable-report.html in test-output folder and select the option open with the web browser.

Let us consider the below scenario which has three methods passTest, failTest and skipTest with @Test annotation.

Step 1: Launch the Eclipse

Step 2: Create a New Package

Step 3: Create a New Java Class “EmailReport”

package testngpackage;

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

public class EmailReport {
//To make it pass
public void passTest(){
//To make it fail
public void failTest(){
//To make it skip
public void skipTest(){
throw new SkipException("Skipping - This method is skipped testing ");

Step 4: Create a TestNG.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "">
<suite name="testngpackage" parallel="methods">
<test name="testngTest">
<class name="testngpackage.EmailReport" />

Step 5: Execute the testng.xml file and refresh the project. You could see your project as below image.


Expand ‘test-output’ folder and you should find a report ”emailable-report.html‘ which is the default report generated by TestNG.


Step 6: Right-click on emailable -report.html and select open with and click on web browser


Report will be like as shown below:


Method 2: index.html

Expand ‘test-output’ folder and you find an option ”index.html‘ which is the default report generated by TestNG.


Right-click on index.html and select open with and click on web browser


Report will be like as shown below:


Method 3: Reporter Class

Along with the above two methods to generate reports, you can use the file to store the system-generated logs as well as user-generated logs. Using Reporter Class is one of the simplest ways to store log information in testing. Reporter class is an inbuilt class in TestNG. It helps in storing the logs inside the reports which are user-generated or system-generated so that in the future when we look at the report, we can directly view the logs from there instead of rerunning the test cases.

Reporter is a class present in TestNG. It has four different methods to store log information:

  1. Reporter.log(String s);
  2. Reporter.log(String s, Boolean logToStandardOut);
  3. Reporter.log(String s, int level);
  4. Reporter.log(String s, int level, Boolean logToStandardOut);

Following syntax is used to use the reporter class


Simply we need to call the “log” function of the Reporter class of TestNG.


Create a class as GoogleTest and write the following code inside the classes.

package com.sampletestpackage;

import org.openqa.selenium.WebDriver;
import org.testng.Reporter;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class GoogleTest {

WebDriver driver;
@Test(priority = 1) 
public void driverSetup()
// System.setProperty("webdriver.gecko.driver", "src\\main\\java\\com\\browserdrivers\\geckodriver.exe");
System.setProperty("", "src\\main\\java\\com\\browserdrivers\\chromedriver.exe");
//System.setProperty("", "src\\main\\java\\com\\browserdrivers\\IEDriverServer.exe");

driver=new ChromeDriver(); 
Reporter.log("The browser is opened");

@Test(priority = 2) 
public void getURL()
     // System.out.println("Launching Google site"); 
      Reporter.log("The Google Site is Launched");

@Test(priority = 3) 
public void getTitle()
  String title = driver.getTitle(); 
      Reporter.log("Prints the web page title");

@Test(priority = 4) 
public void closeBrowser()
  //System.out.println("Test successfully passed"); 
      Reporter.log("Close the driver");


  • Now, Create testng.xml file by selecting the class and
  • Select run as and
  • Click on convert to Testng.
  • Then run this testng.xml file by selecting run as and select Testng suite.
  • Then refresh the project and open the test-output folder.
  1. In the test-output folder and Right-click on open the emailable-report.html. It will look like:

2. In test-output folder, Right-click on index.html and select open with and click on web browser


Click on Reporter output. It will open logging information that is written in the test methods.


Click on “Times”. It will show how much time it took to run the test method present in class.


Generating Allure Reports using TestNG in Selenium Automation

Following are the steps to generate Allure Reports using TestNG

Step1: Create a New Maven project and Update pom.xml with required dependencies from

  • TestNG
  • Selenium Java
  • Webdrivermanager
  • Allure-TestNG

TestNG Dependencies

<!-- -->

Selenium Java

<!-- -->


<!-- -->


<!-- -->

Step2: Download Maven and Allure Binaries then set the path

Go to  and download and extract the zip folder (

Click on Extracted folder and go to bin folder and copy the path and set the maven path in environment variables

Right-click on My PC->Properties -> Click Advance System Settings -> Click Environment Variables – > Click Path under System Variables and click Edit -> Click New and paste the path C:\apache-maven-3.6.3\bin

To check whether maven is configured or not, go to the command prompt and type the command mvn –version.

To download Allure Binaries go to and click Maven Central under Manual Installation and download the latest version 2.13.0 and click on the ZIP folder

Click on Extracted folder and go to bin folder and copy the path and set the path in environment variables.

Right-click on My PC->Properties -> Click Advance System Settings -> Click Environment Variables – > Click Path under System Variables and click Edit -> Click New and paste the path C:\allure-2.13.0\bin

To check whether Allure is configured or not, go to the command prompt and type the command  allure –version.

Step3: Create TestNG Test Cases and run through TestNG.XML

  1. Create a New Package (allureReports)
  2. Create a New Class (Tests)
Package allureReports;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;

Public class Tests {
WebDriver driver;
Public void setup()
driver = new  ChromeDriver();

Public void logoPresence()
Boolean disstatus = driver.findElement(By.xpath(“//div[@class=’header-logo’]//a//img”)).isDisplayed();
Assert.assertEquals(disstatus, true);
Public void loginTest()
driver.findElement(By.linkText(“Log in”)).click();
driver.findElement(By.xpath(“//input[@class=’button-1 login-button’]”)).click();
Assert.assertEquals(driver.getTitle(), “nopCommerce demo store”);

Public void teardown()

Step4: Create a TestNG.xml  file

Right-click on your Testcase(Tests)- >Go to TestNG-> Click Convert to TestNG and click Finish

<?xml  version “1.0” encoding-“UTF-8”?>
<suite name = “Suite”>
<test thread-count=”2” name=”Test”/>
<class name = “allureReports.Tests”/>
</test> <!- - Test- - >
</suite> <!- - Suite - - >

Right-click on TestNG.xml file ->Run As->TestNg Suite

Refresh your project and you can see a new folder allure results. Expand the allure results and you can see json files. To see the allure reports which are generated for test case through TestNG.xml we need to run a command allure serve

Right-click on allure results folder – > Go to Properties – > Copy the Location

Open Command prompt and type the command

Allure serve C:\Users\admin\eclipse-workspace\AllureReporting\allure-results.

It will automatically generate the Allure Reports.

Facebook Comments

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button