Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconFull Stack Developmentbreadcumb forward arrow iconHow to Generate Extent Reports in Selenium

How to Generate Extent Reports in Selenium

Last updated:
21st Sep, 2022
Views
Read Time
12 Mins
share image icon
In this article
Chevron in toc
View All
How to Generate Extent Reports in Selenium

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.

Ads of upGrad blog

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”);

Explore our Popular Software Engineering Courses

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.

Explore Our Software Development Free Courses

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.

In-Demand Software Development Skills

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

Source

Read our Popular Articles related to Software Development

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.

Ads of upGrad blog

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.

Profile

Rohan Vats

Blog Author
Software Engineering Manager @ upGrad. Passionate about building large scale web apps with delightful experiences. In pursuit of transforming engineers into leaders.

Frequently Asked Questions (FAQs)

1What is a Selenium report builder?

Selenium Report Builder or Selenium IDE is a Firefox plugin for Selenium which helps to create and edit the Selenium test cases. It makes the automation process to be more efficient and reduces the effort needed to create different reports. It is a comfortable way to run tests and provides an overview of the current status. Reports are generated in various formats such as text, PDF, CSV, HTML etc.

2What can be tested automatically using Selenium?

Selenium is a tool for automating web applications for testing purposes, and can be used for regression testing. Selenium can automate anything a user can do in a browser. Most websites have some kind of functionality that makes it easier for their employees to accomplish tasks like ordering inventory, processing orders, updating the website, etc. Selenium can be used to test web-based applications and websites. It is a high-level language which supports various programming languages like JAVA and C#. Selenium is used to automate browser and provides web application developers with the ability to write automated tests to be run against web applications.

3What is Selenium Grid?

Selenium Grid is a tool that allows running automated tests across several browsers (or other grid nodes). It allows for parallel execution of these tests with several configurations (locations, browsers, operating systems) and several browsers at once. The tests themselves can be run in headless mode so as to not require any GUI at all. The Grid offers asynchronous job execution and is capable of managing hundreds of jobs concurrently. Selenium grid is thus a hub and spoke model for running test cases. Grid allows users to pool multiple browsers to run a single test case. Once set up, it can be used to run tests across multiple machines or browsers on demand or on a schedule. Selenium Grid can be used to parallelize test execution, scale testing and increase test coverage.

Explore Free Courses

Suggested Blogs

Full Stack Developer Salary in India in 2024 [For Freshers & Experienced]
907173
Wondering what is the range of Full Stack Developer salary in India? Choosing a career in the tech sector can be tricky. You wouldn’t want to choose
Read More

by Rohan Vats

15 Jul 2024

SQL Developer Salary in India 2024 [For Freshers & Experienced]
902296
They use high-traffic websites for banks and IRCTC without realizing that thousands of queries raised simultaneously from different locations are hand
Read More

by Rohan Vats

15 Jul 2024

Library Management System Project in Java [Comprehensive Guide]
46958
Library Management Systems are a great way to monitor books, add them, update information in it, search for the suitable one, issue it, and return it
Read More

by Rohan Vats

15 Jul 2024

Bitwise Operators in C [With Coding Examples]
51783
Introduction Operators are essential components of every programming language. They are the symbols that are used to achieve certain logical, mathema
Read More

by Rohan Vats

15 Jul 2024

ReactJS Developer Salary in India in 2024 [For Freshers & Experienced]
902674
Hey! So you want to become a React.JS Developer?  The world has seen an enormous rise in the growth of frontend web technologies, which includes web a
Read More

by Rohan Vats

15 Jul 2024

Password Validation in JavaScript [Step by Step Setup Explained]
48976
Any website that supports authentication and authorization always asks for a username and password through login. If not so, the user needs to registe
Read More

by Rohan Vats

13 Jul 2024

Memory Allocation in Java: Everything You Need To Know in 2024-25
74112
Starting with Java development, it’s essential to understand memory allocation in Java for optimizing application performance and ensuring effic
Read More

by Rohan Vats

12 Jul 2024

Selenium Projects with Eclipse Samples in 2024
43493
Selenium is among the prominent technologies in the automation section of web testing. By using Selenium properly, you can make your testing process q
Read More

by Rohan Vats

10 Jul 2024

Top 10 Skills to Become a Full-Stack Developer in 2024
229998
In the modern world, if we talk about professional versatility, there’s no one better than a Full Stack Developer to represent the term “versatile.” W
Read More

by Rohan Vats

10 Jul 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon