#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Selenium Frameworks

Set up TestNG, Maven and Selenium for Eclipse

Installing TestNG in Eclipse

Install the TestNG plugin via Eclipse Marketplace (Help > Eclipse Marketplace > search "TestNG"), which adds TestNG project templates and run configurations.

Adding Maven Dependencies

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>3.141.59</version>
</dependency>
<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>7.9.0</version>
</dependency>

Why This Combination Matters

Together, Maven manages dependencies, TestNG structures test execution, and Selenium drives the browser — forming the standard stack for Java-based web UI automation.

Creating the Maven Project in Eclipse

Before adding any dependency, make sure Eclipse is pointing to a JDK, not just a JRE. Current Selenium 4 releases need Java 11 or newer, so check Window > Preferences > Java > Installed JREs and select a JDK.

  1. Choose File > New > Maven Project, tick "Create a simple project", and click Next.
  2. Enter a Group Id such as com.example and an Artifact Id such as ui-tests, then Finish.
  3. Open pom.xml and add the dependencies and plugin shown below.
  4. Right-click the project and select Maven > Update Project so Eclipse downloads the libraries.

A Modern pom.xml for Selenium 4 and TestNG

The snippet on this page shows an older Selenium 3 version. New projects should use Selenium 4, which includes Selenium Manager to download the right browser driver automatically, so you no longer have to set webdriver.chrome.driver by hand. Always pick the latest stable versions from Maven Central; the numbers below are examples.

<properties>
    <maven.compiler.release>17</maven.compiler.release>
    <selenium.version>4.25.0</selenium.version>
    <testng.version>7.10.2</testng.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>${testng.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.2.5</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

Keeping versions in <properties> means you upgrade in one place. The Surefire plugin is what lets mvn test run your TestNG suite outside Eclipse, for example on a CI server.

Writing and Running the First Test

Create a class under src/test/java. Test classes belong there, not in src/main/java, because the TestNG dependency uses the test scope.

package com.example.tests;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.*;

public class HomePageTest {
    private WebDriver driver;

    @BeforeMethod
    public void setUp() {
        driver = new ChromeDriver();   // Selenium Manager finds the driver
    }

    @Test
    public void titleShouldContainExample() {
        driver.get("https://example.com");
        Assert.assertTrue(driver.getTitle().contains("Example"));
    }

    @AfterMethod
    public void tearDown() {
        if (driver != null) driver.quit();
    }
}

Then add a testng.xml file in the project root:

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="UI Suite">
  <test name="Smoke">
    <classes>
      <class name="com.example.tests.HomePageTest"/>
    </classes>
  </test>
</suite>

Run it with right-click on testng.xml and Run As > TestNG Suite, or from a terminal with mvn clean test. Results appear in the TestNG view and in target/surefire-reports.

Setup Problems and How to Fix Them

  • "No compiler is provided in this environment" means Eclipse is using a JRE. Switch the project to a JDK.
  • Red errors on imports after editing the POM usually clear after Maven > Update Project. If not, check for a typo in a group or artifact id.
  • Mixing a manual driver path with Selenium 4 can load an outdated driver. Remove old System.setProperty lines unless you truly need a specific binary.
  • Tests not found by mvn test often means the class is in the wrong folder or the suite file path in Surefire is incorrect.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course