How to Generate Extent Reports in Selenium
Updated on Dec 27, 2024 | 12 min read | 10.0k views
Share:
For working professionals
For fresh graduates
More
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
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.
The following values are used to indicate the status of a test: PASS, SKIP, FAIL, and INFO.
There are a number of advantages of using extent report selenium. Here are some of them-
The extent reports in selenium contain a couple of major classes. These are used very frequently.
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”);
A few prerequisites for generating an extent report are:
Basic steps that are required to follow for the generation of extent reports are:
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:
@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.
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.File);
File Dest = new File(“scr/../Errimages/” + System.currentTimeMillis()+ “.png”);
String errflpath = Dest,getAbsolutePath();
Fileutils.copyFile(scrFile, Dest);
returnerrflpath;
test.log(LogStatus.Fail,test.addScreenCapture(capture(driver))+ “Test Failed”);
upGrad’s Exclusive Software Development Webinar for you –
SAAS Business – What is So Different?
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
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.
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:
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.
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.
Get Free Consultation
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
Top Resources