Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

This TestNG guide will help you in creating a TestNG.xml file and then executing multiple test cases in parallel on a Selenium Grid.

Faisal Khatri
January 13, 2026
TestNG is a framework used for Java automation testing that makes creating and running automated tests much easier. One of its standout features is running tests in parallel using a TestNG.xml file, which expedites software release cycles.
This tutorial on how to create a TestNG.xml file in Eclipse dives deep into how to execute multiple test files from a single file known as the TestNG.xml file. Also, it explores creating a TestNG.xml file in Eclipse.
Generating TestNG reports in Jenkins allows teams to effectively monitor test outcomes and assess build quality in real time. By automating report generation and sharing, it streamlines the CI/CD workflow and improves visibility across development and QA teams.
Why Use TestNG?
TestNG is a powerful testing framework for Java that offers flexible test configuration, parallel execution, and comprehensive reporting. These features make it ideal for creating reliable and scalable automated test suites.
TestNG Results Plugin
The TestNG Results plugin in Jenkins parses TestNG XML files and presents test execution data in an easy-to-read format. It provides summaries, trends, and detailed information on test failures directly on the Jenkins dashboard.
How to Generate TestNG Reports in Jenkins
To generate reports:
Installing TestNG Reports Plugin in Jenkins
How to Share TestNG Reports in Jenkins
TestNG.xml is a configuration file that allows for organizing and executing the automated tests. It helps customize the test execution, including test suites, methods, parameters, and groups.
TestNG allows you to create multiple test cases simultaneously, and that is where the TestNG.xml file eases this task of writing various test cases all within single or multiple classes using TestNG Annotations.
The TestNG.xml file allows running tests in parallel, which could help the software teams save time and get faster feedback on the builds.
Here are the reasons to use the TestNG.xml file:
Prioritizes the test methods
TestNG.xml can be used to prioritize the test methods inside the test block. The TestNG.xml file allows for the specification of the tests in the order in which they need to be executed. This helps organize and efficiently run the test in the required order.
Allows parameterization in the tests
XML file allows parameterization, using which values used in the tests using the @Parameters annotation can be provided using the <parameter> tag in the TestNG.xml file.
A classic example for this case would be cross browser testing, where the browser placeholder is updated in the tests using @Parameters annotation, and multiple test blocks can be created in the TestNG.xml file.
To learn more about it, you can go through this blog on TestNG parameterization.
Provides parallel test execution
Another advantage of the TestNG.xml file is parallel testing. Using the parallel tag, test blocks under the test suite can be executed in parallel.
<suite name="LambdaTest ECommerce Tests" parallel="tests">
It can also help in parallel execution of the test methods provided inside each test block.
<test name="ECommerce Website Login tests" parallel="methods">
Provides TestNG listeners
The TestNG listeners can be added to the TestNG.xml file, thus helping to get the minute details about the test execution. This can help automation test engineers easily debug failed tests.
Offers group test execution
The TestNG.xml file allows group execution of the test cases. It will enable the executing the test method in a specific order as updated in the file. Therefore, while performing TestNG testing, the TestNG.xml file allows testers to control the test execution flow.
Note: Run Your Selenium Tests With TestNG on Cloud. Try TestMu AI Today!
Before creating a TestNG.xml file, you need to set up the TestNG project in Eclipse. If you don’t have Eclipse installed, refer to this guide to install TestNG in Eclipse.
Shown below are the steps:







Let’s now create a new TestNG class. This test will be executed using TestNG.


Select the annotation as required. We have selected the @BeforeMethod and @AfterMethod annotations, which we will use in the test.
A new test class will be added as per the details provided in Step 2. You may notice the red marks in the test class. Hover the mouse over the error line, for example, on @Test annotation. Once the annotation is added, the errors will disappear.


The tests will be executed using TestNG, and the results will be shown in the console window at the bottom.

Subscribe to the TestMu AI YouTube Channel and stay updated with the latest video tutorials on Selenium Java.
In the above section, we set up a TestNG.xml file and executed tests using TestNG. Now, let’s look at how to create a TestNG.xml file in Eclipse.
There are two methods to create a TestNG.xml file:
Method 1:




Method 2:


This is what a basic TestNG.xml file looks like.

You have your very first TestNG.xml file ready. Now you know how to create a TestNG.xml file in Eclipse. Let’s leverage this TestNG.xml file to run automated tests using automation testing tools like Selenium. If you want to dig further and explore the true capabilities of Selenium, check out this guide on what is Selenium.
The hierarchy of an XML file goes like this- first <suite> tag, second <test> tag, and lastly, <classes> tag. You can give any name to the <suite> and <test> tags, but you have to be careful while naming classes since it combines the package and test name.
Since the suite is the topmost hierarchy, this is where multiple test classes can be placed. Let’s understand with the help of an example. For the test scenarios below, we have created two Java classes wherein both tests will run on the TestMu AI eCommerce Playground website.
Test Scenario 1:
Test Scenario 2:
Implementation:
The following code will help implement test scenarios 1 and 2. The EcommercePlayGroundTests class has both test methods to implement the test scenarios.
There are two additional methods in the class. The first one is the setup() method, which will run before any test runs and help set up the WebDriver and start the Chrome browser. The second tearDown() method will gracefully close the WebDriver session.
In case you want to know more about WebDriver, you can go through this tutorial on what is Selenium WebDriver.
public class EcommercePlaygroundTests {
private WebDriver driver;
@BeforeTest
public void setup() {
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
}
@Test
public void testCheckTitle() {
driver.get("https://ecommerce-playground.lambdatest.io/");
final String title = driver.getTitle();
assertEquals(title, "Your Store");
}
@Test
public void testSearchForProduct() {
driver.get("https://ecommerce-playground.lambdatest.io/");
WebElement searchBox = driver.findElement(By.name("search"));
searchBox.sendKeys("iphone");
WebElement searchBtn = driver.findElement(By.cssSelector("button.type-text"));
searchBtn.click();
String pageTitle = driver.findElement(By.cssSelector("#product-search h1")).getText();
assertEquals(pageTitle, "Search - iphone");
}
@AfterTest
public void tearDown() {
driver.quit();
}
}

The testCheckTitle() method will implement the Test Scenario 1, whereas the testSearchForProduct() method will implement the Test Scenario 2.
Test Execution:
Let’s create the TestNG.xml file with the name testng-demo.xml and update both test method names to execute the tests.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testng.xml demo">
<test name="LambdaTest e-commerce playground tests" parallel =”methods”>
<classes>
<class name="io.github.mfaisalkhatri.testngxmldemo.EcommercePlaygroundTests">
<methods>
<include name="testCheckTitle"/>
<include name="testSearchForProduct"/>
</methods>
</class>
</classes>
</test>
</suite>
In the TestNG.xml file above, there are 2 test methods that have the <include> tag and belong to the EcommercePlaygroundTests class. When this file is executed, both tests will run in parallel in the order in which they are updated.
First, the testCheckTitle() method will run, next the testSearchForProduct() method will be run. To run the tests methods in parallel, we need to update the parallel = “methods” tag in the <test> tagline.
To run the project using the XML file, right-click on the testng.xml file and select Run As > TestNG Suite.

This will execute and run both of the tests using testng.xml with a simple click. Following is the test execution result displayed in the console.

Now that you have executed your TestNG.xml file successfully. As mentioned earlier, this file helps running tests in parallel. So, it is important to note the changes you need to make in the TestNG.xml to perform automation testing. However, configuring hundreds of browsers and operating systems in your nodes doesn’t look feasible enough.
Instead, you can leverage a cloud grid offered by TestMu AI. It is an AI-powered test orchestration and execution platform that lets developers and testers perform Selenium automation testing with TestNG on over 3000+ real browsers and operating systems online. That way, you only need to focus on writing better Selenium automation scripts without worrying about test infrastructure needs.

Deliver immersive digital experiences with Next-Generation Mobile Apps and Cross Browser Testing Cloud
Let’s use the same test scenario we implemented in the earlier section of the blog, where we searched for a product on the TestMu AI eCommerce Playground website. Earlier, we ran the tests on the local Chrome browser.
Test Scenario:
Implementation:
A new test class, Base.java, has been created to take care of all the configurations related to running tests on the TestMu AI cloud grid. It will also take care of starting and closing the browsers.
The values for the browser name, version, and platform name will be provided on runtime using the testng.xml file.
The setup() method will update the browser, its version, and platform name as the values are set using the @Parameters annotation in TestNG.
public class Base {
RemoteWebDriver driver;
String status = "failed";
@BeforeTest
@Parameters({"browser", "browserVersion", "platform"})
public void setup(String browser, String browserVersion, String platform) {
final String userName = System.getenv("LT_USERNAME") == null ? "LT_USERNAME" : System.getenv("LT_USERNAME");
final String accessKey = System.getenv("LT_ACCESS_KEY") == null ? "LT_ACCESS_KEY" : System.getenv("LT_ACCESS_KEY");
final String gridUrl = "@hub.lambdatest.com/wd/hub";
if (browser.equalsIgnoreCase("chrome")) {
try {
this.driver = new RemoteWebDriver(new URL("http://" + userName + ":" + accessKey + gridUrl), getChromOptions(browser, browserVersion, platform));
} catch (final MalformedURLException e) {
System.out.println("Could not start the chrome browser on LambdaTest cloud grid");
}
} else if (browser.equalsIgnoreCase("firefox")) {
try {
this.driver = new RemoteWebDriver(new URL("http://" + userName + ":" + accessKey + gridUrl), getFirefoxOptions(browser, browserVersion, platform));
} catch (final MalformedURLException e) {
System.out.println("Could not start the firefox browser on LambdaTest cloud grid");
}
}
this.driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
}
private ChromeOptions getChromOptions(String browser, String browserVersion, String platform) {
var browserOptions = new ChromeOptions();
browserOptions.setPlatformName(platform);
browserOptions.setBrowserVersion(browserVersion);
browserOptions.setCapability("LT:Options", getLtOptions());
return browserOptions;
}
private FirefoxOptions getFirefoxOptions(String browser, String browserVersion, String platform) {
var browserOptions = new FirefoxOptions();
browserOptions.setPlatformName(platform);
browserOptions.setBrowserVersion(browserVersion);
browserOptions.setCapability("LT:Options", getLtOptions());
return browserOptions;
}
private HashMap<String, Object> getLtOptions() {
final var ltOptions = new HashMap<String, Object>();
ltOptions.put("project", "Selenium ECommerce playground website");
ltOptions.put("build", "LambdaTest Ecommerce Website tests");
ltOptions.put("name", "Search for a product test");
ltOptions.put("w3c", true);
ltOptions.put("visual", true);
ltOptions.put("w3c", true);
ltOptions.put("plugin", "java-testNG");
return ltOptions;
}
@AfterTest
public void tearDown() {
this.driver.executeScript("lambda-status=" + this.status);
this.driver.quit();
}
}
The capabilities required for configuration can be set using the TestMu AI Automation Capabilities Generator.
Code Walkthrough:
The getLtOptions() method will set the required capabilities in the test scripts.
Next, a new test class ECommercePlaygroundTestsOnCloud, has been created to implement the test scenario and extend the Base class.
public class ECommercePlaygroundTestsOnCloud extends Base{
@Test
public void testSearchForProduct() {
driver.get("https://ecommerce-playground.lambdatest.io/");
WebElement searchBox = driver.findElement(By.name("search"));
searchBox.sendKeys("iphone");
WebElement searchBtn = driver.findElement(By.cssSelector("button.type-text"));
searchBtn.click();
String pageTitle = driver.findElement(By.cssSelector("#product-search h1")).getText();
assertEquals(pageTitle, "Search - iphone");
status = "passed";
}
}
The testSearchForProduct() method will search for the product iphone from the website’s home page. After loading the search page, it will check that the page title equals Search- iphone.
If everything works fine, the status variable will be updated to passed.
Test Execution:
Let’s create a new TestNG.xml file and name it as testng-parallel.xml. That will help to perform Selenium testing on two different browsers and platforms in parallel.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testng.xml demo" parallel="tests">
<test name="LambdaTest e-commerce playground tests on Windows 10 - Chrome">
<parameter name="browser" value="chrome"/>
<parameter name="browserVersion" value="125"/>
<parameter name="platform" value="Windows 10"/>
<classes>
<class name="io.github.mfaisalkhatri.testngxmldemo.ECommercePlaygroundTestsOnCloud">
<methods>
<include name="testSearchForProduct"/>
</methods>
</class>
</classes>
</test>
<test name="LambdaTest e-commerce playground tests on macOS Sonoma - Firefox">
<parameter name="browser" value="firefox"/>
<parameter name="browserVersion" value="126"/>
<parameter name="platform" value="macOS Sonoma"/>
<classes>
<class name="io.github.mfaisalkhatri.testngxmldemo.ECommercePlaygroundTestsOnCloud">
<methods>
<include name="testSearchForProduct"/>
</methods>
</class>
</classes>
</test>
</suite>
The parallel = “tests” will execute both tests in parallel.
The details of the test execution can be found on the TestMu AI Web Automation Dashboard.

In this blog on how to create a TestNG.xml file in Eclipse, we discussed the importance of using the TestNG.xml file.
With the TestNG.xml file, testers can organize the tests, customize and run the tests in parallel, and group the tests. It also helps in the parameterization of the tests and provides more visibility towards the test execution.
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance