DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk6 min

How to Create a TestNG Project in Eclipse and Run Selenium Tests

Build a Maven-managed Java test project in Eclipse, add TestNG and Selenium, run a browser test from the IDE or Maven, and troubleshoot driver setup.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a Maven Java project in Eclipse, add TestNG and Selenium as dependencies, then run a TestNG test from the IDE or with Maven. For current Selenium releases, you can usually start without downloading a browser driver manually: Selenium Manager can find and cache one when needed. This guide walks through both setup paths and the issues most likely to stop a first test from running.

What you need before you begin

  • Eclipse with Maven integration. The steps below use a Maven project so dependencies and versions are recorded in pom.xml.
  • A Java installation supported by the releases you choose. The TestNG Eclipse plugin documentation specifies Eclipse 4.2 or newer, and Java 11 or newer for plugin 7.8.0 and later; those are plugin requirements, not a compatibility guarantee for every Selenium and TestNG release combination. See TestNG’s Eclipse plugin documentation.
  • A supported browser installed on the machine where the test will run.

TestNG supplies test annotations and execution; Selenium WebDriver controls the browser. Installing the Eclipse plugin does not add the TestNG runtime library to your project.

Create a Maven project in Eclipse

  1. In Eclipse, choose File → New → Maven Project. If the wizard is not available, check that Eclipse’s Maven integration is installed.
  2. Choose a workspace location and, if offered, a simple project archetype. Enter a group ID and artifact ID, then finish the wizard.
  3. Confirm the project has a pom.xml and a test source directory, usually src/test/java. If Eclipse has not recognized it as a Maven project, right-click the project and choose Configure → Convert to Maven Project where available.

Maven keeps the dependency declarations with the project, making it easier to run the same test setup outside Eclipse. TestNG’s Maven guidance recommends integrating with Surefire: TestNG with Maven. Selenium also documents adding its Java library with a build tool: Selenium Java library installation.

Add TestNG and Selenium dependencies

Add TestNG with test scope and Selenium’s Java library to the project’s pom.xml. Versions change, so check the official release and installation pages and choose versions compatible with your installed Java runtime rather than copying an old tutorial’s numbers. TestNG’s Maven page has a dependency example; Selenium’s Java page directs readers to its current downloads information.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<dependencies>
  <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>YOUR_TESTNG_VERSION</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>YOUR_SELENIUM_VERSION</version>
  </dependency>
</dependencies>

Replace both version values with actual compatible releases before saving. In Eclipse, save the file and allow Maven to update the project. If dependencies do not appear, right-click the project and choose Maven → Update Project.

Install the TestNG plugin for Eclipse

The plugin adds IDE features such as a TestNG test wizard, launch configurations and a results view. It is useful for authoring and running tests in Eclipse, but the Maven dependency above is still required for the project itself.

  1. Open Help → Eclipse Marketplace, search for TestNG, and install the TestNG plugin; or choose Help → Install New Software and use the official update site: https://testng.org/testng-eclipse-update-site.
  2. Complete the installation and restart Eclipse when prompted.
  3. Verify that TestNG actions are available, for example by opening File → New and checking for the TestNG test wizard.

The TestNG project describes the plugin as a way to run tests from Eclipse and monitor execution and output. See the plugin documentation for its current installation and launch options.

Write a browser test

Create a Java class under src/test/java, using a package that matches your project structure. This minimal example opens a public page, checks its title, and quits the browser even if the assertion fails:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
package example;

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

public class HomePageTest {
    @Test
    public void pageHasExpectedTitle() {
        WebDriver driver = new ChromeDriver();
        try {
            driver.get("https://example.com");
            Assert.assertTrue(driver.getTitle().contains("Example Domain"));
        } finally {
            driver.quit();
        }
    }
}

Use a URL and assertion appropriate to the site you are testing. driver.get navigates to the page; Selenium’s locators can then find elements for interaction and assertions. The finally block calls quit() to end the WebDriver session and close its browser windows. Selenium’s first-script guide shows the basic browser-session pattern: Selenium first script.

Run the test from Eclipse or Maven

Run a class or method in Eclipse

  1. Right-click HomePageTest.java in the Package Explorer.
  2. Choose Run As → TestNG Test.
  3. Review the TestNG results view and Eclipse’s Console for the run status, failures and error details.

The TestNG plugin also supports launch configurations for a class, group, XML suite or individual method. Use Run → Run Configurations when you need to choose a specific target or configure the launch.

Run through Maven

From the project directory, run:

mvn test

This uses the project’s Maven test configuration, including Surefire when it is configured for TestNG. It is a useful check that the test can run through the build path rather than only through an IDE launch. Eclipse and Maven runs can differ if their suite XML, JVM properties, environment variables or plugin configuration are not aligned.

Do you need to download a browser driver?

WebDriver needs a browser and a matching driver component. With modern Selenium releases, start by letting Selenium Manager handle a missing driver: it is included with Selenium and can be invoked by the bindings to discover, download and cache drivers. In the example, new ChromeDriver() is the normal starting point; a separate manual driver download is not always necessary.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This depends on Selenium Manager being able to access the information and downloads it needs, and on a compatible browser being available. In restricted networks, or when a team must pin a specific driver, configure the driver explicitly or provide it on PATH according to the Selenium documentation: Selenium Manager.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common setup failures

Eclipse cannot find TestNG annotations or imports

Installing the Eclipse plugin alone does not add TestNG to the Maven project. Confirm that the TestNG dependency is in pom.xml, then update the Maven project and check that dependency resolution completed.

The test class does not appear or run

Place the class under src/test/java, confirm it contains a method annotated with @Test, and verify there are no compilation errors. If using an XML suite, check that the class or package is included in that suite.

ChromeDriver or another driver fails to start

Confirm the browser is installed and supported by the Selenium release. Check the exception text and network access if Selenium Manager cannot resolve or download a driver. In a controlled environment, configure a known driver through the appropriate Selenium Service or PATH setup rather than relying on automatic discovery.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The Java version or dependencies are rejected

Check the Java runtime Eclipse uses as well as the one Maven uses in the terminal; they may differ. Select Selenium and TestNG versions supported by that runtime. The TestNG plugin’s Java 11+ requirement for versions 7.8.0 and newer does not establish the full compatibility matrix for the project libraries.

Eclipse passes but mvn test fails, or vice versa

Compare the selected test class or suite, Maven Surefire settings, system properties and environment variables. An IDE launch can use Eclipse-specific runtime settings, while Maven uses the build configuration in the project.

Or skip the browser setup

If you need a screenshot of a webpage rather than an interactive Selenium test, ScreenshotNeo can return an image or PDF with one API request. It is not a replacement for Selenium when a test must interact with a browser, click controls or verify application behavior.

For example, with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for options and response details. It removes cookie banners, newsletter popups and chat widgets before capture; bot checks, blank pages and failed loads are not billed. Its MCP server lets AI agents use screenshot tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.