Selenium

Convert Selenium Main Method to TestNG & Add System Info in Extent Reports – Complete Guide

Convert Selenium Main Method to TestNG & Add System Info in Extent Reports

By Bhau Automation • Professional Automation Reporting with TestNG & Extent Reports

🎯 What You Will Learn in This Video

  • How to convert Selenium main() method script into TestNG
  • Why TestNG is better than main method execution
  • How to add system information in Extent Reports
  • Display OS, User Name, Java Version, Selenium Version, Browser
  • Enhance automation report professionalism

📌 Why Convert Main Method to TestNG?

Most beginners start Selenium automation using the main() method. But professional frameworks always use TestNG because:

  • Better test management
  • Annotations support (@Test, @BeforeMethod, @AfterMethod)
  • Parallel execution
  • Easy integration with Extent Reports
  • Detailed reporting

📌 Example: Main Method Script

public class LoginTest {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        System.out.println("Application Launched");
        driver.quit();
    }
}

📌 Converted to TestNG

import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LoginTestNG {

    @Test
    public void launchApp() {
        WebDriver driver = new ChromeDriver();
        driver.get("https://example.com");
        System.out.println("Application Launched using TestNG");
        driver.quit();
    }
}

📊 Adding System Information in Extent Reports

Adding system information makes your report more professional and informative.

  • Operating System
  • User Name
  • Java Version
  • Selenium Version
  • Browser Name

🛠 Java Code – Add System Info in Extent Reports

ExtentSparkReporter spark = new ExtentSparkReporter("target/SystemInfoReport.html");
ExtentReports extent = new ExtentReports();
extent.attachReporter(spark);

extent.setSystemInfo("OS", System.getProperty("os.name"));
extent.setSystemInfo("User Name", System.getProperty("user.name"));
extent.setSystemInfo("Java Version", System.getProperty("java.version"));
extent.setSystemInfo("Selenium Version", "4.20.0");
extent.setSystemInfo("Browser", "Chrome");

ExtentTest test = extent.createTest("System Info Demo Test");
test.pass("System information added successfully");

extent.flush();

🔗 Integrate Extent Reports with TestNG

TestNG + Extent Reports combination gives you powerful reporting features:

  • Automatic logging
  • Pass/Fail status
  • Test execution time
  • System environment visibility

🎯 Real-World Use Cases

  • Enterprise automation frameworks
  • CI/CD pipeline reporting
  • Client demo reports
  • Management dashboards
  • Cross-browser execution reports

🎥 Watch Full Video Tutorial

👉 Convert Selenium Main Method to TestNG + Add System Info

✅ Key Takeaways

  • Main method is for learning, TestNG is for professionals
  • System info makes your reports more meaningful
  • Extent Reports improves test visibility
  • Must-have skill for QA automation engineers
Pro Tip: Always add environment details in reports – it helps debugging and auditing.

🚀 Created with ❤️ by Bhau Automation

Back to All Articles