Generating Comprehensive Test Reports with Selenium and ExtentReports

You are currently viewing Generating Comprehensive Test Reports with Selenium and ExtentReports

Selenium has many reporting features, including inbuilt reports that use frameworks such as TestNG and JUnit. Although a few reports are built in, they don’t provide any information about the steps executed as part of the test suite. Custom reporting is needed to make the process convenient for all project stakeholders.

Testers must configure these reports so they are useful to the entire team. The idea of creating Extent Reports may be confusing to someone who has never used them before. This guide, with examples, will help you understand how to generate Extent Reports using Selenium webDriver.

Let’s get started!

What are Test Reports in Automation?

A report is a 100% completion of a task. The report is not just a summary but also helps summarize and visualize the results. Reports are also important in testing automation. Test automation reports help testers and other stakeholders understand the stability of tests performed before the product is launched. This report helps stakeholders understand the stability and provides confidence in going live.

The automation test report must be created in a manner that clearly explains the results to the user. A good test report will include various statistics, such as the number of automation tests, the number of tested cases that passed, the number of cases that failed, and the percentages of both passed and failed cases.

Various reporting tools have been available to generate test automation reports in recent years. These include Reports, JUnit Reports, Allure Reports, etc.

Extent Reports, which many organizations widely use, is among the most popular reporting tools for Selenium. Its unique features, such as report customization, integration of different test frameworks, and amazing data visualization, have made it a popular tool.

What are Extent Reports?

Extent Report is a library that generates test reports for automated testing. The enhanced features and customization have made it more popular for report generation than the built-in reports of various test frameworks. It is a powerful yet simple reporting library that can be integrated into the automation framework to generate the test report.

Extent Reports are also compatible with other popular frameworks for test automation, such as JUnit and TestNG. It gives a detailed overview of the automated test cases. Extent Reports can be easily integrated with automation frameworks.

Advantages of Extent Reports

Here are the benefits of using Extent Reports for Selenium automation testing.

  • This is an open-source library.
  • It shows a visual representation of test results.
  • You can customize it to your needs.
  • The users can attach screenshots and logs to the test report to get a more detailed overview of the tests.
  • It is easy to integrate with other frameworks, such as JUnit and TestNG.
  • You can easily configure it with Jenkins, Bamboo, etc.

How to Generate Extent Reports in Selenium?

We will generate our first Extent Report using Selenium Java for our automation test. Please read our Selenium Java Tutorial for more information. Let’s see what is required to set up and create Extent Reports within Selenium during test execution.

Java: Download and Install Java on your PC.

Selenium: Installing Selenium is required to frame our automation test cases. This can be done by adding a maven dependency to the pom.xml.

Extent Reports: We need to add the Extent Report as either a maven or jar dependency to integrate our automation framework. Add maven dependency to the pom.xml in a maven-based project.

You can download the jar and add it to the build path. Refer to the repository when adding the Extent Report as a dependency.

TestNG: TestNG will be used to design and execute tests. We have now set up Selenium to automate a web app and generate the Extent Reports.

How do you Generate and Customize the Extension Reports?

Three classes are available in Selenium for customizing and generating the Extent Reports. These are:

  • ExtentHtmlReporter
  • Reports on Extent
  • ExtentTest

ExtentHtmlReporter creates an HTML file and accepts the file path as a parameter. The file path is the path where our extended report will be generated.

ExtentHtmlReporter htmlReporter =  new

ExtentHtmlReporter(System.getProperty(“user.dir”)+”/Reports/extentReport.html”);

The getProperty() method returns a system property specified by the string key. This key is passed in as an argument. Here, we have specified “user.dir” as the key, and System.getProperty(“user.dir”) returns our current working directory.

So, instead of specifying the full path, we can use this to fetch the value of our directory and add the path where we want our Extent Report in Selenium to be saved.

ExtentHtmlReporter is also used to customize the extent reports. The config() method allows for many configurations. Below are some of the configurations you can make.

Step 1: To set the title of the extent report, we can use setDocumentTitle(“YOUR_TITLE”).

Step 2: To set the report name, we can use setReportName(“YOUR_REPORT_NAME”).

Step 3: SetTimeStampFormat() allows us to specify the time format in our report.

Extent Reports can be customized using the setTheme() function if you’re a fan of dark themes. Our extent reports can be customized using two themes: STANDARD or DARK.

To summarize:

  • ExtentHtmlReporter is the class used to create HTML reports.
  • Create the tests using ExtentReports.
  • ExtentTest is the class that generates the logs for the Extent Report.

We have now seen how to configure the Extent Reports using Selenium. The ExtentHtmlReporter can be initialized, and the configurations can be added to the @BeforeTest testNG annotation.

Generating Extent Reports in Selenium Using a Cloud Grid?

We have already written a few simple test cases to learn the basics of Extent Reports. Let’s automate some test cases using Selenium to generate our automation report. We will use our Cloud Selenium Grid to execute tests like LambdaTest.

LambdaTest, an AI-powered test orchestration and execution tool that supports Selenium Grid, can run our tests on the grid. LambdaTest, a test automation platform, offers an online farm with 3000+ browsers for Selenium Automation testing.

All our tests will be run on the LambdaTest Playground, which allows us to explore different pages and learn automation.

Test Case 1: Verify the title of the page

Step 1: Launch https://www.lambdatest.com/selenium-playground/.

Step 2: Get the title of the web page and verify it.

Test Case 2: Enter single input and check the message displayed

Step 1: Launch https://www.lambdatest.com/selenium-playground/.

Step 2: Click Simple Form Demo under the Input Forms Section.

Step 3: Enter your message in the Enter Message Text Box.

Step 4: Click on the button to Get the checked value.

Step 5: Check the message in the section Your Message.

Test Case 3: Enter multiple inputs to verify the displayed value

Step 1: Launch https://www.lambdatest.com/selenium-playground/.

Step 2: Click Simple Form Demo under the Input Forms Section.

Step 3: Enter the values of a and B in the section for the two input fields.

Step 4: Click on the Get Values button.

Step 5: Verify that the total a+b value is correct.

Test Case 4:  Verify alert message on a Web Page

Step 1: Launch https://www.lambdatest.com/selenium-playground/.

Step 2: Click Bootstrap Alerts under the Alerts & Modals section.

Step 3: Click the Normal Success Message to verify it is displayed.

We have understood that the scenarios are to be automated. Divide them into two classes: InputFormTest with the first three scenarios and AlertTests with the last.

Code Walkthrough

Step 1: Initialize global variables

Initialize global variables in BaseClass.

Step 2: Initialize the extent report.

Create the method initializeReport(), which contains the steps for initializing and configuring Extent Reports within Selenium.

Step 3: Include common methods. BaseTest allows us to add commonly used techniques, such as capturing screenshots. These can be used in various tests.

How do I Execute Parallel Tests in Selenium and Generate Extent Reports?

Parallel testing, as the name implies, runs the test methods/tests in parallel instead of sequentially. Parallel execution is preferred for automation because it reduces test execution time. Parallel execution can be applied at the process, class, test, and instance levels.

Methods: This will run parallel tests for all @Test methods within TestNG.

Tests: This value will be used for all test cases in the tag.

Classes: Tests for all courses in XML that are present will be run in parallel.

Instances: This value runs all test cases in parallel within the same instance.

Generate Extent Reports in Selenium using Jenkins.

Jenkins has become a popular open-source DevOps Tool for Continuous Integration and Continuous Delivery Processes. It is a Java-based application and platform-independent. It is a tool for building code from the source repository, performing unit tests, and sending build reports to a member or team.

Follow the steps below to generate Extent Reports using Jenkins in Selenium:

Step 1:Click Manage Jenkins after logging in to Jenkins.

Step 2: Install the HTML Publisher plug-in.

Step 3: The HTML Publisher plugin will appear in the tab Installed.

Step 4: After installing the plugin, restart Jenkins.

Step 5: Click on New Item to create a project.

Step 6: Integrate your GitHub Account in the Source Code Management section. This allows us to run tests on Jenkins and pull code from GitHub.

Step 7: Select the Publish HTML Reports under Add Post-Build Action in the Post-Build Actions Section.

Please provide the folder where you would like your report to be generated and the name and title of the Extent Report.

Step 8: Save your changes.

Step 9: Click on Build Now.

Step 10: You will see a task being created within the project.

Step 11: As shown in the screenshot below, you will see ExtentReport within the project once the build is complete.

Step 12: Click on ExtentReport.

Step 13: The generated Extent Report is now displayed. The Extent Report can be accessed to analyse the test execution.

End Note

Integrating a reporting framework with our automation framework. Automation testers use Extent Reports to generate and share the test report with organizational stakeholders.

Test reports are important for automation. It is better to have an excellent report that shows the test summary in a graphical format. Extent Reports provide an overview of the tests executed and pie charts that depict the summary in a visual format.

Extent Reports can be easily replaced by any existing reporting tool in an automation framework. Extent Reports are very easy to use and provide extraordinary test reports. This article will be informative and help you integrate the reporting tool seamlessly into your automation framework.

  • Post published:February 27, 2024
  • Post author:
  • Post category:Technology

Leave a Reply