In Selenium automation testing, merging two Extent Reports can be beneficial when you want to consolidate test results from different runs or scenarios into a single comprehensive report. This tutorial will guide you through the detailed process and provide practical examples for quick understanding.
Understand How to Merge Two Extent Reports
There are two common ways to achieve our goal: One is by using the code, and another is by using the ExtentX UI to merge. Let’s go through both these methods one by one.
Merge Extent Reports By Using the Code
Let’s understand the first method. Here is an in-depth explanation of how you should do it.
Section 1: Setting Up Your Project
Begin by ensuring you have a Selenium project set up with Extent Reports integrated. If you haven’t installed the Extent Reports library, you can do so using your preferred package manager (e.g., Maven or Gradle). Make sure to have the main dependencies in your project.
Section 2: Understand Extent Reports
Before diving into merging reports, let’s have a quick overview of Extent Reports. Extent Reports is a reporting library for Selenium WebDriver, offering detailed HTML reports with interactive charts and graphs.
Section 3: Generate Extent Reports
Assuming you have a Selenium test suite that generates Extent Reports after execution, ensure each test class creates its individual Extent Report file. This is crucial for later merging.
Here’s a simplified example of how to generate Extent Reports in Selenium. This code has two demo tests, each generating an individual report file.
import com.aventstack.extentreports.*; import org.testng.annotations.*; public class SampleTest { private static ExtentReports ext; @BeforeSuite public void setUp() { // No need to config ExtentHtmlReporter for each test method extent = new ExtentReports(); } @Test public void sampleTestCase1() { // Your test logic here // Log steps ExtentTest demo = ext.createTest("Demo Test 1"); demo.log(Status.INFO, "Step 1: Do an action"); demo.log(Status.INFO, "Step 2: Verify the result"); // Add more logs as needed } @Test public void sampleTestCase2() { // Your logic here // Log steps ExtentTest demo = ext.createTest("Demo Test 2"); demo.log(Status.INFO, "Step 1: Do another action"); demo.log(Status.INFO, "Step 2: Verify another result"); // Add more logs as needed } @AfterSuite public void tearDown() { // Flush the Extent Report ext.flush(); } }
Ensure each test class follows a similar structure, creating its Extent Report file during test execution.
Try Our Free Tools: Merge PDF Files for Free
Section 4: Merge Reports
Now, let’s proceed to the core part – merging two Extent Reports. For simplicity, we’ll use the ExtentReports utility class provided by the Extent Reports library.
import com.aventstack.extentreports.*; public class ReportMerger { public static void main(String[] args) { try { // Create ExtentReports instances ExtentReports merged = new ExtentReports(); // Specify the paths of the reports to be merged String rptPath1 = "path/to/first/report.html"; String rptPath2 = "path/to/second/report.html"; // Create ExtentHtmlReporter instances for the reports to be merged ExtentHtmlReporter rpt1 = new ExtentHtmlReporter(rptPath1); ExtentHtmlReporter rpt2 = new ExtentHtmlReporter(rptPath2); // Load the reports to be merged merged.attachReporter(rpt1, rpt2); // Display a message in the merged report ExtentTest mergedTest = merged.createTest("Merged Test"); mergedTest.log(Status.INFO, "This report is a combination of two individual reports."); // Flush the merged report merged.flush(); } catch (Exception e) { e.printStackTrace(); } } }
Replace "path/to/first/report.html"
and "path/to/second/report.html"
with the actual paths of the Extent Reports you want to merge. This example creates a new Extent Report file, attaches the reports to be merged, and adds a custom message.
Section 5: Run the Merged Report
Execute the ReportMerger
class to generate the merged Extent Report. Open the resulting HTML file in your preferred web browser to view the consolidated results.
Let’s explore another way to merge Extent Reports without delving into code. This method involves using the Extent Reports framework itself. No coding is needed; you just follow some simple steps.
Using Extent Reports Framework
Install ExtentX:
Get ExtentX, a reporting server for Extent Reports, provides historical views of your test runs.
Configure ExtentX:
Set up ExtentX by following its documentation and connecting it to your existing Extent Reports.
Run Tests and Reports:
Run your Selenium scripts as usual, ensuring each run generates a separate Extent Report.
Access ExtentX Dashboard:
Open the ExtentX dashboard in your web browser.
Merge Reports in ExtentX:
ExtentX offers an easy way to merge reports through its user interface.
Head to the “Reports” section and select reports for merge operation. Use the merge option to create a comprehensive report.
This method gives a hassle-free approach for merging two Extent reports without any coding. ExtentX serves as a centralized hub for managing and analyzing your Extent Reports.
Must Read:
1. What is Regression Testing? How to Do It? Provide Examples.
2. What is Penetration Testing? How to Do It? Provide Examples.
3. What is the Software Development Life Cycle (SDLC)?
4. What is the Software Testing Life Cycle (STLC)?
5. How to Generate Report in Selenium Webdriver?
6. How to Generate Extent Report in Selenium?
7. How to Zoom In/Out in Selenium Webdriver Using Java?
8. Random API for Postman to Generate Random Inputs
Summary
Merging two Extent Reports in Selenium is a valuable practice for aggregating test results. This tutorial aimed to simplify the process, making it accessible for Selenium testers. Feel free to adapt the examples to fit your project’s structure and requirements.
Happy testing!