Master Software Testing & Test Automation

Extent Reporting: A Comprehensive Guide to Test Automation

Extent Report Framework

Extent Reporting: Generate extent reports in Selenium Webdriver

 

Extent Reporting  is a popular open-source reporting library used for generating interactive and detailed HTML reports for test automation. It is widely used in conjunction with Selenium, a popular test automation framework, to create comprehensive and visually appealing test reports. The library is designed to provide a simple and intuitive way of generating reports that both technical and non-technical stakeholders can easily interpret.

 

Extent Reporting

The ExtentReports class is the core of the Extent Report library. It provides a set of APIs that can be used to create and customize reports, add logs, screenshots, and other artifacts to the report, and generate the final report in various formats. The library also supports advanced features such as parallel testing, grouping of test cases, and tagging, which makes it a powerful tool for reporting on large and complex test suites.

 

Extent Reports is an open-source reporting library widely used in Selenium automation for generating rich and interactive HTML reports. Integrating Extent Reports with Selenium WebDriver enhances the reporting capability of automated tests, providing detailed insights into each test case. To generate Extent Reports in Selenium, one typically includes the ExtentReports jar file in their project. This library works seamlessly with testing frameworks like JUnit and TestNG, making it a versatile tool for test reporting.

In a typical Selenium test automation framework, you start by creating a public class for your test script. Within this test class, you define WebDriver ‘driver’ and ExtentReports ‘reports’ object instances. To avoid existing data being overwritten, you can configure the reports object to create a new report for every test execution or append to an existing report. The test class also includes ExtentTest ‘test’ instances for each test case, which are used to log test steps and results. The test status, whether a test passes or fails, is captured and displayed in the HTML report. For instance, you can use ‘public static String’ to define a directory to store the resultant HTML file.

The process of generating Extent Reports in Selenium WebDriver involves a few key steps. First, you initialize the reports object and specify the path where the HTML file will be stored. During test execution, every test case is recorded using the ExtentTest object. After the execution of each test script, flushing the report is crucial to ensure that all information is written to the HTML report.

This HTML report provides a comprehensive view of the test status and includes the capability to add additional information, such as a message to be printed onto the report. In cases where a test fails, the report can include screenshots for further analysis. Thus, Extent Reports serve as a powerful guide to generating detailed and informative HTML reports based on Selenium test execution, significantly aiding in the review and analysis of automated test cases.

With Extent Report, developers and testers can easily create detailed and informative reports that help them identify issues and track the progress of their test automation efforts. The library’s user-friendly interface and extensive documentation make it easy to get started with, even for those with little or no experience in test reporting. Overall, Extent Report is a valuable tool for anyone looking to improve their test automation reporting capabilities.

Why Is Reporting Important in Selenium-Based Test Automation?

Reporting forms the backbone of a robust Selenium-based automation framework. Effective test reports translate technical execution into easily digestible insights for all stakeholders, from developers to project managers. With well-structured reports, teams can quickly gauge an application’s overall health, spot failing test cases, and trace issues back to specific steps or scenarios.

Leveraging detailed reports—especially those enriched with logs and screenshots—enables teams to:

  • Diagnose failures efficiently by pinpointing the exact moment and reason a test faltered.
  • Communicate progress and results clearly to both technical and non-technical team members.
  • Monitor trends across multiple runs, making identifying recurring glitches or flaky tests easier.

Ultimately, thorough reporting transforms raw test results into actionable intelligence, supporting informed decision-making and continuous quality improvement throughout the development lifecycle.

Generate extent reports in selenium webdriver

Extent Reports

 

Extent Reports is a popular reporting library used by developers to generate interactive and comprehensive reports for their test automation projects. In this section, we will cover the basics of getting started with Extent Reports, including installation and configuration, and creating your first report.

Installation and Configuration

To use Extent Reports in your project, you need to add the ExtentReports library as a dependency in your project’s pom.xml file. If you are using Maven, you can add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>5.0.6</version>
</dependency>

Alternatively, you can download the jar file from the official website and add it to your project’s classpath.

Once you have added the ExtentReports library to your project, you can start using it in your code. To create a new Extent report, you need to create an instance of the ExtentReports class. You can use either the ExtentHtmlReporter or ExtentSparkReporter class to generate HTML or Spark reports, respectively.

Creating Your First Test Reports

To create your first Extent report, you need to create an instance of the ExtentTest class and start a new test using the startTest method. You can then use the createTest method to create a new test and attach it to the Extent report.

ExtentReports extent = new ExtentReports();
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("test-output/ExtentReport.html");
extent.attachReporter(htmlReporter);

ExtentTest test = extent.createTest("My First Test", "This is a sample test");
test.log(Status.INFO, "Starting test...");
test.log(Status.PASS, "Test passed successfully");

extent.flush();

In the above example, we first create an instance of the ExtentReports class and attach an instance of the ExtentHtmlReporter class to it. We then create a new test using the createTest method and attach it to the Extent report using the attachReporter method. Finally, we log some information and a pass status to the test and flush the report using the flush method.

Overall, getting started with Extent Reports is a straightforward process. By following the steps outlined in this section, you can quickly generate interactive and comprehensive reports for your test automation projects.

Building Blocks to enable the use of extent reports

The ExtentTest Object

The ExtentTest object is the fundamental building block of Extent Reports. It represents a single test in the report and is responsible for logging all the events that occur during the test execution. The ExtentTest object can be created using the createTest() method of the ExtentReports class. Once created, the object can be used to log various types of events such as logs, info, test status, etc.

Managing Tests and Logs

The ExtentTest object provides various methods to manage tests and logs. These methods include log(), info(), pass(), fail(), skip(), etc. The log() method is used to log a message to the report. The info() method is used to log an informational message to the report. The pass(), fail(), and skip() methods are used to log the status of the test.

The ExtentTest object also provides various log methods such as addScreenCapture(), addScreencast(), etc. These methods are used to add screenshots and screencasts to the report. The ExtentTest object also provides a flush() method, which is used to flush the logs to the report.

Overall, the ExtentTest object is the most important building block of Extent Reports. It provides various methods to manage tests and logs and is responsible for logging all the events that occur during the test execution.

Enhancing Reports

Extent Report provides a variety of features to enhance the quality of reports generated. This section will cover two of the most important features that can be used to customize and improve reports: Adding Screenshots and Media, and Customization and Styling.

Adding Screenshots and Media

One of the most useful features of Extent Reports is the ability to add screenshots and media to the report. This can be done easily by using the addScreenCapture method, which takes a screenshot of the current screen and adds it to the report. This feature is especially useful when trying to debug a test that has failed, as it allows the user to see exactly what went wrong.

To add a screenshot to a report, simply call the addScreenCapture method and pass in the path to the screenshot. The screenshot will then be added to the report along with any other information that has been logged.

Generate extent reports using s=Selenium webdriver and TestNG

Creating a Java code that incorporates all the specified keywords and concepts into a single program can be quite extensive. However, I’ll provide an example that demonstrates the basic structure of such a program, focusing on integrating Extent Reports with Selenium and TestNG for generating test reports. This example assumes familiarity with Selenium WebDriver, TestNG framework, and Extent Reports library.

Please note that the actual implementation might vary based on the specific version of the libraries and tools you are using. Also, this example does not include detailed test scenarios but rather focuses on the setup and basic usage of Extent Reports in a Selenium TestNG framework.

 import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

 

public class SeleniumExtentReportExample {
private WebDriver driver;
private static ExtentReports reports;
private static ExtentTest test;

@BeforeClass
public static void setUpBeforeClass() {
// Initialize ExtentReports with a file path for the HTML report
reports = new ExtentReports(“path/to/report.html”, true); // ‘true’ to overwrite the existing report
}

@BeforeClass
public void setUp() {
// Set up WebDriver
System.setProperty(“webdriver.chrome.driver”, “path/to/chromedriver”);
driver = new ChromeDriver();
}

 

@Test
public void testExample() {
test = reports.startTest(“testExample”, “This is an example test using Extent Reports with Selenium 4”);

driver.get(“https://www.example.com&#8221;);
test.log(LogStatus.INFO, “Navigated to example.com”);

// Add test steps here
// …

test.log(LogStatus.PASS, “Test passed”);
reports.endTest(test);
}

 

@AfterClass
public void tearDown() {
// Close the WebDriver
if (driver != null) {
driver.quit();
}
}

@AfterClass
public static void tearDownAfterClass() {
// Write the test information to the report
reports.flush();
reports.close();
}
}

 

In this code:

  • We import the necessary classes from Selenium WebDriver, TestNG, and Extent Reports libraries.
  • We initialize the ExtentReports and ExtentTest objects.
  • We set up a basic test with TestNG and Selenium, logging information to the Extent Test object.
  • After the test execution, we flush the report to ensure all information is written to the HTML file.
  • The HTML report generated is customizable and will reflect the test execution status and details as logged in the test methods.

Remember to replace "path/to/report.html" and "path/to/chromedriver" with the actual paths on your system. This is a basic example and can be expanded with more complex test cases, data-driven reports, and additional Extent Reports features as needed.

Customization and Styling

Extent Reports also provides a variety of options for customizing and styling reports. Users can add custom logs, change the title of the report, and even change the styling of the HTML file that is generated.

To add custom logs to a report, simply call the log method and pass in the message that you want to log. This can be useful for adding additional information to a report that is not captured by the default logging.

To change the title of a report, simply call the setReportName method and pass in the new title. This can be useful for making reports more descriptive and easier to understand.

 

Finally, users can also customize the styling of the HTML file that is generated by using the config method. This method allows users to change a variety of settings, including the color scheme, font, and layout of the report.Overall, Extent Reports provides a variety of features for enhancing the quality of reports generated. By using features like adding screenshots and media, and customization and styling, users can create reports that are both informative and visually appealing.

 

Advanced Usage and Best Practices

Integrating Test Reports with Test Frameworks

Extent Report is designed to work with various test frameworks, including TestNG Framework , JUnit, and Cucumber framework. By integrating with these frameworks, users can generate detailed and interactive reports for their test runs.

To integrate with TestNG, users can simply add the Extent TestNG Listener to their test suite. This can be done by adding the following code to the testng.xml file:

<listeners>
    <listener class-name="com.aventstack.extentreports.testng.listener.ExtentITestListenerClassAdapter" />
</listeners>

Similarly, for JUnit, users can add the Extent JUnit Runner to their test suite. This can be done by adding the following code to the @RunWith annotation:

@RunWith(ExtentRunner.class)

For Cucumber, users can use the Extent Cucumber Adapter to generate reports. This can be done by adding the following code to the Cucumber runner class:

@CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})

Continuous Integration and Deployment

Extent Report can also be integrated with Continuous Integration and Deployment (CI/CD) tools such as Jenkins to automate the report generation process.

Users can configure Jenkins to run their test suite and generate the report after each build. This can be done by adding the following code to the Jenkinsfile:

stage('Test') {
    steps {
        sh 'mvn test'
    }
}

stage('Report') {
    steps {
        sh 'mvn com.aventstack.extentreports:extentreports-maven-plugin:3.1.5:aggregate'
    }
}

This will run the test suite and generate the report using the Maven plugin. The report will be available in the target/surefire-reports/ExtentReports folder.

Overall, integrating Extent Report with test frameworks and CI/CD tools can help users generate detailed and interactive reports for their test runs, making it easier to identify and fix issues.

General FAQ on Extent Reports

What features does Extent Reports offer?

Extent Reports comes packed with a variety of features that enhance test reporting in automation frameworks. These include visually appealing pie charts to summarize test results at a glance, detailed logs to track every step of the process, and the capability to capture and display screenshots for better issue tracking. Additionally, its intuitive design and versatile reporting options make Extent Reports a go-to tool for comprehensive and effective test documentation.

How do you view the generated Extent Report after test execution in Katalon Studio?

To view the generated Extent Report after executing tests in Katalon Studio, follow these steps:

  1. Access the Reports Folder: Navigate to the folder where your test reports are saved.
  2. Locate the HTML File: Find the specific .html file corresponding to your recent test execution.
  3. Open the HTML Report: Double-click the .html file or open it in your preferred web browser to view the detailed test report.

This will display a comprehensive summary of your test execution, including pass/fail status and other relevant metrics.

How to Execute a Test Suite with Extent Reports in Katalon Studio

Executing a test suite with Extent Reports in Katalon Studio requires setting up test listeners that will initialize and generate the reports post-execution. Follow these steps to get started:

  1. Setup Test Listeners:
    • Open the Tests Explorer in Katalon Studio.
    • Navigate to Test Listeners > New > New Test Listener.
    • Provide a name for your new test listener, such as <mark style="color: #272B32; border-width: 1px; border-radius: 4px; box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 1px 2px -1px rgba(0, 0, 0, 0.1); background-color: #E9D5FF; border-color: #C084FC;">ExtentReportsListener</mark>, and click OK.
  2. Implement the Test Listener Script:
    • Copy the following code into the new test listener:
import com.kms.katalon.core.annotation.AfterTestCase;
import com.kms.katalon.core.annotation.AfterTestSuite;
import com.kms.katalon.core.annotation.BeforeTestCase;
import com.kms.katalon.core.annotation.BeforeTestSuite;
import com.kms.katalon.core.context.TestCaseContext;
import com.kms.katalon.core.context.TestSuiteContext;

class ExtentReportsListener {

  @BeforeTestSuite
  def setupBeforeTestSuite(TestSuiteContext testSuiteContext) {
    CustomKeywords.'com.katalon.extent.report.ExtentReport.deleteFolderContents'();
    CustomKeywords.'com.katalon.extent.report.ExtentReport.attachEReport'(testSuiteContext, "Extent Report", "KS QA Test Report");
  }

  @BeforeTestCase
  def setupBeforeTestCase(TestCaseContext testCaseContext) {
    CustomKeywords.'com.katalon.extent.report.ExtentReport.startEReport'(testCaseContext);
  }

  @AfterTestCase
  def teardownAfterTestCase(TestCaseContext testCaseContext) throws IOException {
    CustomKeywords.'com.katalon.extent.report.ExtentReport.takeScreenshotFailure'(testCaseContext);
  }

  @AfterTestSuite
  def teardownAfterTestSuite() {
    CustomKeywords.'com.katalon.extent.report.ExtentReport.flushEReport'();
  }
}
  1. Customize Your Report:
    • Within the attachEReport method, you’ll need to specify your desired report title and name:
    CustomKeywords.'com.katalon.extent.report.ExtentReport.attachEReport'(testSuiteContext, "Your Report Title", "Your Report Name");
    
  2. Run Your Test Suite:
    • Once the listener setup is complete, run your test suite as usual in Katalon Studio.
    • The custom listener will handle the setup and teardown processes, ensuring that Extent Reports are generated automatically after the test execution.

Key Points to Remember:

  • The @BeforeTestSuite and @BeforeTestCase annotations are used to perform actions prior to running the test suite and test cases, respectively.
  • The @AfterTestCase and @AfterTestSuite annotations help with post-execution actions, such as taking screenshots on test failure and flushing the report to finalize it.

By following these steps, you’ll be able to execute your test suite in Katalon Studio with integrated Extent Reports, providing you with a detailed overview of your test execution results.

How Does Integrating Extent Reports Benefit Katalon Studio Users?

Integrating Extent Reports with Katalon Studio offers a range of benefits that significantly enhance the efficiency and clarity of test reporting.

Firstly, Extent Reports provides visually appealing formats such as pie charts and logs, which make it easier to interpret test data at a glance. This helps teams quickly identify key metrics and performance indicators without wading through text-heavy logs.

Secondly, these reports include features like screenshots, which bring an added layer of transparency to the test outcomes. By visually capturing the state of the application at various checkpoints, Katalon Studio users can better diagnose issues and validate results.

Moreover, Extent Reports streamline the entire test reporting process, making it more cohesive and organized. This seamless integration means you no longer have to rely solely on Katalon’s built-in reports. Instead, you get a more comprehensive, navigable overview of your test results.

Key Advantages of Using Extent Reports:

  • Open Source & Flexible: Extent Reports is an open-source reporting library, so you can integrate it freely and tailor it to your team’s specific requirements.
  • Customizable Presentation: The reports aren’t just functional—they’re customizable, allowing you to adjust visuals and content as you see fit.
  • Rich Visuals: Pictorial representations, including pie charts, make it much easier to digest complex test outcomes.
  • Framework Integration: Extent Reports supports easy integration with popular frameworks such as JUnit, TestNG, and NUnit, so it fits naturally into most automation workflows.
  • Detailed Logging & Screenshots: Detailed logs and the ability to attach screenshots—especially for failed test steps—give you a granular, transparent view of your tests.
  • Comprehensive Test Summaries: Extent Reports’ detailed summary helps you quickly spot issues, successes, and trends.

In summary, integrating Extent Reports enhances Katalon Studio by offering clear, visually engaging reports that simplify understanding test results and identifying issues promptly. Detailed logging, visual feedback, and broad compatibility make it a standout choice for teams seeking better insights into their test automation efforts.

What custom keywords does Katalon Studio support for Extent Reports?

Katalon Studio offers two specific custom keywords for enhancing Extent Reports:

  1. Attaching Logs to Test Steps: This keyword allows you to append a log to any test step, making it easier to document and review each individual step in your report. You can use it as follows:
    CustomKeywords.'com.katalon.extent.report.ExtentReport.attachLog'("Add Test Description Here")
  2. Adding Screenshots to Test Steps: This keyword enables you to capture and embed screenshots directly into your test steps. This is particularly useful for visual validation and debugging. To use this keyword, you simply call:
    CustomKeywords.'com.katalon.extent.report.ExtentReport.addScreenshot'()

In addition to these custom keywords, Extent Reports provides a set of built-in methods to bolster your reporting workflow further:

  • startTest: Use this method to define and execute any preconditions for a test case, ensuring your setup is correctly captured in the report.
  • endTest: This method wraps up the postconditions of your test case, marking its completion in the Extent Report.
  • Log: Throughout your test, you can log the status of each step, making it easier to trace progress and pinpoint issues.
  • Flush: Once your test execution is complete, the flush method ensures that all report data is written to the output file, clearing any temporary memory and finalizing the report.

These features collectively enhance the detail and usability of your Extent Reports, providing thorough insights into each test step’s performance while keeping your test documentation organized and actionable.

How to Open a Test Case and Add Custom Keywords for Extent Reports in Katalon Studio

To open a test case and integrate custom keywords for Extent Reports in Katalon Studio, follow these steps:

  1. Open Your Test Case: Open the test case to which you want to add custom keywords from the ‘Test Explorer’ panel in Katalon Studio.
  2. Insert Custom Keywords:
    • Log Attachment: To attach logs to a specific test step, use the following custom keyword:
      CustomKeywords.'com.katalon.extent.report.ExtentReport.attachLog'("Add Test Description Here")
      
    • Screenshot Capture: To take a screenshot during a test step, utilize this custom keyword:
      CustomKeywords.'com.katalon.extent.report.ExtentReport.addScreenshot'()
      
  3. Place Keywords in Corresponding Steps: Copy and paste these custom keyword snippets into the relevant test steps where you want to capture execution events.
  4. Execute the Test Case: Finally, include this test case in a test suite and run the suite to execute the test case with the integrated Extent Report keywords.

By following these steps, you’ll successfully add custom keywords for Extent Reports, allowing for enhanced logging and screenshot capture within Katalon Studio.

How do you create a new Test Listener in Katalon Studio?

Creating a new Test Listener in Katalon Studio is straightforward. Follow these steps:

  1. Navigate to the Tests Explorer: Open Katalon Studio and go to the Tests Explorer panel.
  2. Select Test Listeners: Within the Tests Explorer, find and select the ‘Test Listeners’ option.
  3. To create a New Test Listener, Click on the ‘New’ button and select ‘New Test Listener’ from the dropdown menu.
  4. Name Your Test Listener: A prompt will appear asking for a name. For instance, you can name it ‘ExtentReportsListeners.’ Click on ‘OK’ once you’ve entered the name.
  5. Add Code to the Listener: An editor window will open. Here, you can copy and paste your desired code into the script section of the test listener.

By following these steps, you’ll successfully create and set up a new Test Listener in Katalon Studio, ready for your custom automation needs.

What is the purpose of creating a Test Listener for Extent Reports in Katalon Studio?

The purpose of creating a Test Listener for Extent Reports in Katalon Studio is to automate the process of generating detailed test reports. By setting up these listeners, you ensure that Extent Reports are initialized and produced automatically after each test suite runs. This not only saves time but also provides a comprehensive and professional summary of your test results, making it easier to analyze and share findings.

How can you verify that the Extent Reports plugin is installed successfully in Katalon Studio?

To confirm that the Extent Reports plugin has been successfully installed in Katalon Studio, follow these steps:

  1. Launch Katalon Studio: Open the application as you normally would.
  2. Navigate to the Profile Section: Find and click on ‘Profile’ in the main menu.
  3. Reload Plugins: Select the ‘Reload Plugins’ option to refresh the list of installed plugins.
  4. Check Availability: Look for the Extent Reports plugin in the list to ensure it appears.

By completing these steps, you can verify the successful installation of the Extent Reports plugin in Katalon Studio.

How to Install the Extent Reports Plugin in Katalon Studio?

  1. Download the Plugin: Navigate to the Katalon Store and search for the “Extent Reports” plugin. Click ‘Install’ to download it.
  2. Verify Installation:
    • Open Katalon Studio.
    • Go to the Profile menu located at the top.
    • Select Reload Plugins from the dropdown.
    • Ensure the Extent Reports plugin appears in the list of available plugins.

And that’s it! You’ve successfully installed the Extent Reports plugin in Katalon Studio.

Frequently Asked Questions (FAQ) on Extent Reports in Selenium 4

Q1: What are Extent Reports and their use in Selenium 4? A1: Extent Reports is an open-source reporting library useful for generating customizable HTML test reports in Selenium 4. It is used to create detailed and visually appealing reports that can include data such as test status, logs, and screenshots.

Q2: How do Extent Reports work in Selenium? A2: ExtentReports class generates HTML reports based on the test execution data. The path for these reports can be set as a parameter passed onto the Extent Reports object. The Extent Test class is then used to log information during the test, which gets reflected in the generated report.

Q3: Can I learn how to generate Extent Reports using Selenium and TestNG? A3: Absolutely! You can learn how to generate Extent Reports in Selenium using the TestNG framework. These reports are part of the test execution process and can be customized to include specific details of the test cases.

Q4: What makes Extent Reports unique? A4: Extent Reports are known for their customizable HTML reports. They allow for data-driven reports, which means they can dynamically display data based on the test execution. This feature is particularly useful for detailed analysis and review of test cases.

Q5: What is the typical import statement structure for using Extent Reports in Selenium? A5: Common imports for using Extent Reports with Selenium include:

  • import org.openqa.selenium.WebDriver;
  • import org.openqa.selenium.chrome.ChromeDriver;
  • import com.relevantcodes.extentreports.ExtentReports;
  • import com.relevantcodes.extentreports.ExtentTest;
  • import com.relevantcodes.extentreports.LogStatus;

Q6: Can Extent Reports be integrated with JUnit and TestNG? A6: Yes, Extent Reports can be seamlessly integrated with testing frameworks like JUnit and TestNG. They are capable of generating documents and XML feeds compatible with these frameworks.

Q7: How are reports managed in terms of data storage? A7: When generating a new report, you can configure whether the existing data has to be overwritten or a new report must be generated. The default value for this setting is usually ‘true’, meaning it overwrites the existing report.

Q8: What are some advanced features of Extent Reports in Selenium? A8: Advanced features include capturing screenshots of the current WebDriver state, logging postconditions of the test case, and printing messages onto the resultant report. These features enhance the test reports, providing a comprehensive view of the test execution.

Q9: What is the benefit of using Extent Reports in test automation? A9: The benefit of using Extent Reports in test automation with Selenium is the ability to create custom reports that are both informative and visually appealing. They help in better understanding and analyzing the test execution process and outcomes.

 

Share it :

Leave a Reply

Discover more from Master Software Testing & Test Automation

Subscribe now to keep reading and get access to the full archive.

Continue reading