View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All

How to Generate Extent Reports in Selenium

By Rohan Vats

Updated on Dec 27, 2024 | 12 min read | 10.0k views

Share:

Selenium provides frameworks like TestNG and JUnit, to provide inbuilt reports. Although these built-in extentreports in selenium offer information on all steps that get executed as a part of test cases, these need further customization for being shared with the main project stakeholders.

Extent report selenium is also a customizable variant of an HTML report which can get integrated into the Selenium WebDriver with the use of JUnit and the TestNG frameworks.

Check out our free courses to get an edge over the competition.

The tutorial guides on extent report in selenium you with a complete idea of how to generate Extent Reports in Selenium WebDrive with a few example codes.

The open-source library used for test automation in selenium is ExtentReports. Testing frameworks; NUnit, JUnit, etc can be integrated with the library. In-built reports are created in selenium through the frameworks of TestNG and JUnit, but Extent reports are still the first choice of the Automation testers of selenium. The extent reports in selenium give more insight into the execution of the automation scripts. The results are depicted as pie charts and are basically HTML documents. Are details like the snapshots, and custom logs can be generated through the library. 

After the successful run of an automated test, a report of test execution is to be generated by the testers. A default report is provided by the TestNG, but the details are not provided. With the applicability of the ExtentReport API, interactive reports could be generated through simple configurations. Frameworks of Java and .Net such as JUnit, NUnit, and TestNG, etc. are supported by the library.

Check out upGrad’s Advanced Certification in Cloud Computing

Dependency of the extent report maven

Source

The selenium extent reports consists of two classes:

1. ExtentReports class

The tester specifies a path and based on the path specified, HTML reports are generated from the ExtentReports class. Either there is the generation of a new report or the overwriting of an existing report. It is decided based on the Boolean value. The default Boolean value is “true” which means that there will be overwriting of all data that existed in the past.

Check out upGrad’s Advanced Certification in Blockchain

2. ExtentTest class

Test steps are logged through the ExtentTest class onto the HTML reports generated through the above method.

3. Extent HtmlReporter

An HTML file is created by this class.

The listed built-in functions can be used with classes that are listed below.

  • startTest: The preconditions of a case in the test is executed
  • endTest: The postconditions of a case in the test are executed.
  • Log method: The status of every step in the test is logged onto the generated HTML report through the Log.
  • Flush: A new report is created removing the data on a previous report.

The following values are used to indicate the status of a test: PASS, SKIP, FAIL, and INFO.

Advantages Of Extent Report In Selenium

There are a number of advantages of using extent report selenium. Here are some of them-

  • Customisable extent reports in selenium in HTML having stepwise as well as pie chart-based representation.
  • Display of time taken for all test case executions within the extent reports in selenium.
  • Each of the test steps for extentreports in selenium can be associated with screenshots.
  • Multiple test case-based runs within the single suite that can be trackable easily.
  • Extent report in selenium can be integrated with both TestNG and the JUnit frameworks.

Using extent report selenium in Selenium Webdriver

The extent reports in selenium contain a couple of major classes. These are used very frequently.

  • Extentreports in selenium class
  • ExtentTest class

The syntax for the same is listed below-

ExtentReports reports = new ExtentReports(“Path of directory to store the resultant HTML file”, true/false);

ExtentTest test = reports.startTest(“TestName”);

Coverage of AWS, Microsoft Azure and GCP services

Certification8 Months
View Program

Job-Linked Program

Bootcamp36 Weeks
View Program

How to create Extent Reports

A few prerequisites for generating an extent report are:

  • Preinstallation and setup of Java.
  • The installation of TestNG.
  • Downloading of the Extent Report Jars (Version 2.41.2).
  • Requirement of extent-config.xml that allows the configuration of HTML report.

Basic steps that are required to follow for the generation of extent reports are:

  • A testing project is to be created.
  • The extent of the report jar file is to be downloaded.
  • The extent report jar file is added into the project.
  • An implemented class is created.

Steps for Generating an Extent Report

  • The extent reports are able to be generated in WebDriver of selenium through the importation of a jar file which is extentreports-java-2.41.2.jar. The jar file contents are to be extracted into a directory once it gets downloaded.
  • Jar files extracted from the downloaded ZIP file are to be added to the build project. The option Build Path -> Configure Build Path is used.
  • A Java class is newly created for the extent reported through the following code. 

Source

Explanation of the code

With the startTest method, the test execution begins. The object of extent reports is initialized. The extent report object uses any user-defined path as a parameter passed onto it.

@beforeclass: The use of the extent reports is demonstrated by the code. 

@test: The following actions are automated through this class:

  • Opening of the chrome browser through the URL www.google.com.
  • Page title is to be validated with the value as expected once it gets opened.
  • The status of the case of the test is to be logged as a PASS or a FAIL using the extent reports log method.

@afterclass: Code for the execution of a case of test postconditions are included in this class. It includes the code for the test ending or report flushing. Without the use of the method flush(), the extent reports in selenium won’t be generated.

Capture screenshots in Extent Reports

1. Through the method of capture

  • There are several benefits to using a screenshot capture during the test. 
  • If software starts acting erroneously, then the testers could identify the problem through observing the screenshots. 
  • Therefore, if the test execution encounters any issues, the screen captures will allow the testers to debug the test script. 
  • Screenshots should be captured only during the failure of a test, as more memory is consumed by the captures.
  • The following code used for capturing a screenshot is taken from

2. Explanation of the code

  • The current selenium WebDriver is captured as a screenshot through the method of getScreenShotAs(). It is then stored in various forms of output.

File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.File);

  • An object of the file is returned through the method of getScreenShotAs and stored in a variable of the file. For using this method, it is mandatory to cast the instance of the web driver to take a screenshot.

File Dest = new File(“scr/../Errimages/” + System.currentTimeMillis()+ “.png”);

  • A folder with the name of “ErrImages” is created within the folder “src” through the above code. The file is saved in the created folder with the name of the file as the time of the current system.

 String errflpath = Dest,getAbsolutePath();

Fileutils.copyFile(scrFile, Dest);

returnerrflpath;

  • Error images generated are copied in a destination folder.

3. Log Method

  • A built-in method is used in the log method. The addScreenCapture of the class Extent is used to capture a screenshot and then appended to the generated extent reports.

test.log(LogStatus.Fail,test.addScreenCapture(capture(driver))+ “Test Failed”);

Advantages of Extent Reports

  • The use of the extent reports is easy.
  • Pie charts are used for displaying the results.
  • Percentage of a passed case of a test is provided.
  • The ability to add the details of the environment in a natural way.
  • Compared to the other reports, the extent report offers the provision of customization.
  • More interactive reports can be generated through extent API. The interactive reports might be in the form of a graphical view, screenshot capture during every testing step, a dashboard view, and reports that could be emailed.
  • Integration with the JUnit, TestNG, and NUnit frameworks is possible.
  • Parallel execution of test runs is possible with the generation of a single report for all the parallel runs.
  • The report can be configured.
  • For the execution of every test case, the time taken is displayed. 
  • Easy tracking of the runs of multiple test cases in a single suite is possible.
  • Based on the reports of the test, the results can be filtered out. Also, stepwise results can be filtered out through the options of pass/fail/info.
  • Categorizations of reports are provided for categories like Regression/functional, etc.
  • Logs of the test steps can be added to the reports.

upGrad’s Exclusive Software Development Webinar for you –

SAAS Business – What is So Different?

Example of Extent Reports in Selenium

An example is shown to let you understand the process of generation of extent report maven.

Step 1: A maven project and a class is to be created BasicExtentReport.java with the addition of a code available here 

  • A HTML standalone file is generated from the ‘ExtentHtmlReporter’ class. 
  • ‘ExtentHtmlReporter(java.io.File)’ is accepted by this class and  the path ‘ExtentHtmlReporter(java.lang.String filePath)’. 
  • The file path is passed to save the reports. 
  • The method config()of the class ‘ExtentHtmlReporter’ allows various options for configuration. Items can be changed through the code to make changes in the look of the extent report including time stamp, report name, etc.
  • Status for each step of the test is reported by the ‘AfterMethod’ and thereby the status of the test is updated  like Pass, Fail, skip, etc. in the occurrence of any error, a message is generated to give the information. It is done through ‘result.getThrowable()’.
  • Labels of the status are created using the MarkupHelper class that also colors the report status.

Step 2: Passing the OS and parameters of the browser is done through creating a testng.xml file. The code is available on the mentioned website.

Step3: Another code is added to the pom.cml file.

Step4: Running the program generates the resulting report.

Source

For viewing the failure reports, the failed tests are to be clicked. This will display the test status along with the reason for the test failure.

A few additional things related to extent reports are:

  • For the sake of appearance, the theme existing in a report can be changed.
  • As per the convenience of the user, the dashboard view may be hidden or shown.
  • In the case of running multiple tests, a test case can be searched in a step-by-step manner.
  • The total time taken for running the test including the start time and end time is displayed to the user.
  • Additional filters are present in a report. The results can be filtered according to the status of the tests like a passed tests, failed tests or test cases where only information is present.

Learn Software Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Conclusion

For the generation of any customizable reports, the extent reports are the best way. Being an open-source library with an easy configuration with selenium, the extent reports have definitely become the best choice for all the automation testers. The article briefly discussed the extent reports, how to generate them, and their usefulness. The benefits can be reaped out through the knowledge of the software programming which is the basis of the generation of the extent reports.

Extent Reports are used popularly by automation testers in order to generate a test report and then share it ahead with stakeholders in an organization. As a test report plays a vital role in the process of automation, it is mostly better to have reports that are good. A good report is one that can capture completely a test execution summary along with a graphical representation.

Extent Reports don’t just provide a detailed summary of any executed tests but these also provide add-on pie charts for the depiction of test summary in a visual format.

Additionally, it is easy to replace any present reporting tool when you employ Extent Reports in the automation frameworks. Extent Report is indeed a very simple thing, yet it provides extraordinary reports. You can now use the above information to integrate a reporting tool into the automation framework minus any hurdles. Try hands-on Extent Reports in Selenium and keep exploring!

If you are willing to learn and explore the benefits of software programming, check the course of Executive PG Programme in Software Development – Specialisation in Full Stack Development, offered by upGrad. This is a specially designed course for entry-level professionals within the age group of 21 to 45 years. Providing a platform for online lectures and interactive sessions with hands-on experiences, the course provides placement assurance in top industries. Our team is available for any queries.

Frequently Asked Questions (FAQs)

1. What is a Selenium report builder?

2. What can be tested automatically using Selenium?

3. What is Selenium Grid?

Rohan Vats

408 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

upGrad

AWS | upGrad KnowledgeHut

AWS Certified Solutions Architect - Associate Training (SAA-C03)

69 Cloud Lab Simulations

Certification

32-Hr Training by Dustin Brimberry

View Program
upGrad

Microsoft | upGrad KnowledgeHut

Microsoft Azure Data Engineering Certification

Access Digital Learning Library

Certification

45 Hrs Live Expert-Led Training

View Program
upGrad

upGrad KnowledgeHut

Professional Certificate Program in UI/UX Design & Design Thinking

#1 Course for UI/UX Designers

Bootcamp

3 Months

View Program