TestNG Framework for Selenium
Harry
· 21 Sep 2026
· 1 views
Log in to track your progress and mark lessons complete.
Sponsored
Introduction to TestNG
TestNG organises tests with annotations, groups, parallel runs and rich HTML reports. It is the runner behind most Java Selenium frameworks.
Annotations
@BeforeSuite @BeforeClass @BeforeMethod
@Test(priority = 1, groups = "smoke")
@AfterMethod @AfterClass @AfterSuiteAssertions
Assert.assertEquals(actual, expected); Assert.assertTrue(isLoggedIn). A failed assert fails the test and logs expected vs actual.
Groups, DataProvider, Parameters
@Test(groups = {"smoke", "regression"})
@DataProvider(name = "logins")
public Object[][] data() {
return new Object[][] {
{"user@test.com", "Pass@123", true},
{"bad@test.com", "wrong", false} };
}
@Test(dataProvider = "logins")
public void login(String u, String p, boolean ok) { ... }Reports and Parallel Testing
TestNG emits test-output HTML reports; plug ExtentReports for dashboards with screenshots. Run suites in parallel with testng.xml parallel=methods thread-count=4 to cut suite time.
Selenium + TestNG Project Layout
src/test/java/pages/LoginPage.java
src/test/java/tests/LoginTest.java
src/test/resources/testng.xml + testdata.csv- Annotations control order; groups control scope.
- DataProvider turns one test into fifty.
- Parallel runs plus CI equal fast feedback.