The complete guide to enterprise-grade test automation with TestNG and Selenium WebDriver. Annotations, parallel execution, data providers, and Maven integration — built by Aayush Mishra, SDET.
TestNG is a powerful Java testing framework inspired by JUnit and NUnit, designed for modern enterprise test automation at scale.
TestNG (Test Next Generation) was created by Cédric Beust to overcome JUnit's limitations. It introduces powerful features like annotations, data-driven testing, parallel execution, grouping, and dependency management — all essential for enterprise-scale Selenium automation.
When combined with Selenium WebDriver, TestNG becomes the backbone of professional QA pipelines — from simple smoke tests to complex cross-browser parallel regression suites running across 50+ test cases simultaneously.
Used by teams at Google, LinkedIn, and thousands of enterprise QA departments worldwide, TestNG integrates seamlessly with Maven, Jenkins, Allure Reports, and every major CI/CD platform.
import org.testng.annotations.*; import org.openqa.selenium.*; import org.openqa.selenium.chrome.*; public class LoginTest { private WebDriver driver; @BeforeMethod public void setUp() { driver = new ChromeDriver(); driver.get("https://example.com/login"); } @Test(groups = "smoke", priority = 1) public void testValidLogin() { driver.findElement(By.id("username")).sendKeys("admin"); driver.findElement(By.id("password")).sendKeys("secret"); driver.findElement(By.id("loginBtn")).click(); Assert.assertTrue(driver.getTitle().contains("Dashboard")); } @AfterMethod public void tearDown() { driver.quit(); } }
Every TestNG annotation explained — what it does, when to use it, and how it maps to the Selenium test lifecycle.
How TestNG, Selenium, Maven, and your CI/CD pipeline connect into a single enterprise test automation system.
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite name="RegressionSuite" parallel="methods" thread-count="4"> <!-- Global parameters available to all tests --> <parameter name="browser" value="chrome" /> <parameter name="baseUrl" value="https://staging.app.com" /> <!-- Run smoke tests first --> <test name="SmokeTests"> <groups> <run><include name="smoke" /></run> </groups> <classes> <class name="tests.LoginTest" /> <class name="tests.SearchTest" /> </classes> </test> <!-- Full regression in parallel --> <test name="RegressionTests"> <classes> <class name="tests.CheckoutTest" /> <class name="tests.ProfileTest" /> <class name="tests.PaymentTest" /> </classes> </test> </suite>
@DataProvider(name = "loginCredentials") public Object[][] loginData() { return new Object[][] { { "admin@co.com", "Admin@123", true }, // valid { "user@co.com", "wrongPass", false }, // invalid pass { "", "", false }, // empty fields { "sql' OR '1'='1", "anything", false }, // SQL injection }; } @Test(dataProvider = "loginCredentials") public void testLogin(String email, String pass, boolean expected) { // TestNG runs this method 4 times — once per data row loginPage.login(email, pass); Assert.assertEquals(loginPage.isLoggedIn(), expected); }
Simulate running a TestNG test class. Select a test type, enter a class name, and watch the console output — exactly as you'd see in your IDE or CI pipeline.
<dependencies> <!-- TestNG --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.9.0</version> </dependency> <!-- Selenium WebDriver --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.18.1</version> </dependency> <!-- WebDriverManager (auto driver setup) --> <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>5.7.0</version> </dependency> <!-- Allure TestNG Reporter --> <dependency> <groupId>io.qameta.allure</groupId> <artifactId>allure-testng</artifactId> <version>2.25.0</version> </dependency> </dependencies>
Production-grade TestNG patterns used by senior SDETs at top engineering teams worldwide.