ExtentReports in Selenium. (Session-1).

ExtentReports library files used to generate reports in HTML format. These reports show the overall test result in diagrammatic format.

ExtentReports Features:

  1. ExtentReports are open source library files
  2. It can also be easily integrated with TestNG.
  3. Shows result in pie chart form
  4. Generate logs
  5. Test case results with screenshots
  6. Multiple views of the result, based on Test case Result, Tags, category, etc.
  7. Records execution date and time.
  8. Many more other details.

Download Libraries

Download latest version of the library files from below location:

Maven Repository: com.aventstack » extentreports » 5.0.1 (mvnrepository.com)

Help Document

https://www.extentreports.com/docs/versions/5/net/index.html

Supporting Libraries

If encountered java.lang.ClassNotFoundException download and add below libraries files in the project:
1. Download freemaker jar files from

https://www.apache.org/dyn/closer.cgi/freemarker/engine/2.3.31/binaries/apache-freemarker-2.3.31-bin.tar.gz

2. Download reactive java libraries from

https://mvnrepository.com/artifact/io.reactivex.rxjava3/rxjava/3.0.4

3. Download reactive stream libraries from

https://mvnrepository.com/artifact/org.reactivestreams/reactive-streams/1.0.2

ExtentReports Stepwise process

After adding all the required library files now we are ready for coding. There are two important classes used to generate reports.

  1. Reporter Classes: These classes basically provide a template of the report. This means how our report will look like. These templates are basically HTML files. Few classes are:
    • ExtentSparkReporter
    • ExtentAventReporter
    • ExtentEmailReporter
    • ExtentKlovReporter
  2. Logger Class: A logger class is used to log all the events, messages, and information into the Reporter Class objects to generate the reports. ExtentReports class used as a logger here. Below are the few basic methods of ExtentReports objects:
    • attachReporter(reporter): To establish a link between logger and reporter objects.
    • createTest(string): To create a test case.
    • log(Status, String): To define test result status and specific message.
    • flush(): Writes or sends all the test case information to the Reporter object.

Test Case Results via Status Class

Below is the Test Result status which a user can set based on the requirements or based on the workflow of the program.

  1. INFO: Used to log any information. (Please note, that this status is count as Passed test cases.)
  2. PASS: Used to log result as Passed.
  3. SKIP: To mark the status as Skipped.
  4. WARNING: To mark any important information during execution. (This will count as Others in the test result.)
  5. FAIL: To mark test case result as Failed.

Code Example

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;

/**
 * @author ashok.kumar
 *
 */
public class TestA {

	// Defined static, so that we could use these globally in the program.
	static ExtentSparkReporter reporter;
	static ExtentReports logger;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
				
		System.out.println("Exection Started.");
	
		// Initialize the Reporter and set the destination folder and result in HTML format.
		reporter=new ExtentSparkReporter("Reports\\result.html");
		
		// Initialize object of ExternReports which will work as a Logger 
		logger=new ExtentReports();
		
		// Establish a link between Reporter and Logger
		logger.attachReporter(reporter);
		
		// Calling all the test methods.
		TC1();
		TC2();
		TC3();
		TC4();
		TC5();		
		
		System.out.println("Execution Finished");
	}
	
	static public void TC1()
	{
		// Create a Test case with specific name
         logger.createTest("Test Case 1")
     
               // Record the staus of the "Test Result" and the related "information".     
         .log(Status.PASS,"This is first test case Passed.");
              
             // Write the result into the Reporter object.
             logger.flush();
	}
	
	static public void TC2()
	{
		logger.createTest("Test Case 2")
		.log(Status.FAIL,"This is Second test case Failed.");
		logger.flush();
	}
	
	static public void TC3()
	{
		logger.createTest("Test Case 3")
		.log(Status.SKIP,"This is Third test case Skipped.");
		logger.flush();
	}
	
	static public void TC4()
	{
		logger.createTest("Test Case 4")
		.log(Status.WARNING,"This is Forth test case Warning.");
		logger.flush();
	}
	
	static public void TC5()
	{
		logger.createTest("Test Case 5")
		.log(Status.INFO,"This is Fifth test case Information.");
		logger.flush();
	}
}

In the above program, we have set the destination folder as “Reports” with the report name “result.html”. After execution, locate this location and you would be able to open the result.html file in the web browser to view the result.

Report Analysis

There are many pages or Views in the generated report. Which we can select from the Left most panel. But there are two basic views.

List View

The first one is as a List View. In the below screenshot we can observe the below information:

  1. Date of execution: at the top-right corner.
  2. List of all the test cases with Status icons.
  3. Selected Test Case Title/Name
  4. Test Execution Start date/time and finish date/time
  5. Test Case Title with Status, TimeStamp, and Details.
List View Report.

Graphical View

This view contains all the information in pie-chart view.

Graphical View Report

ExtentReports:


Leave a Comment

Your email address will not be published. Required fields are marked *

   YouTube ChannelQuora

            Ashok Kumar is working in an IT Company as a QA Consultant. He has started his career as a Test Trainee in manual testing in August 2010. Then he moves towards the automation testing after 4 years. He started learning JAVA and Selenium by self to get the knowledge of automation.

       While learning these tools and working on multiple projects, he found that sometimes people get stuck in live scenarios in their project and they have to do lots of RnD to get out of it. So he decided to start blogging only for such scenarios, where anyone facing any problem in their project, can ask any question or give a solution or you can say an alternate solution to achieve the goal successfully.

Later on, he observed that some people want to learn Java but they have few questions in their mind like how to start Java, whether we should go for the online or offline course. So he started writing tutorials on Java, Jira, Selenium, Excel etc.