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

Dive into automation testing using Selenium with Java with this detailed tutorial. Master the essentials to begin your Selenium Java testing journey confidently.

Salman Khan
December 26, 2025
Selenium with Java is a widely adopted approach for automating web application testing. It combines the robustness of the Selenium framework with Java’s reliability and strong ecosystem, enabling efficient creation and execution of tests across different web environments.
Selenium with Java is widely used in automation due to Java’s stability, mature tooling, and strong ecosystem support. Its seamless integration with testing frameworks and CI tools makes it ideal for scalable, maintainable test suites.
How to Configure Selenium With Java?
Before you begin automating with Selenium, it helps to understand the basic setup that ensures smooth development. Each step below prepares your environment for testing.
How to Run Selenium Test With Java?
Before running automated tests with Selenium and TestNG, it’s helpful to set up a clear workflow. The steps below outline how to prepare your environment, build your test structure, and validate the execution.
Selenium is a powerful open-source automation framework used for testing modern web applications across browsers, operating systems, and platforms. While it supports multiple programming languages, Selenium with Java is the preferred choice in enterprise environments due to Java’s mature ecosystem, static typing, and strong community support.
Its compatibility with build tools like Maven and Gradle, and IDEs like IntelliJ and Eclipse, makes Java ideal for building structured, scalable test automation frameworks. The widespread adoption of Java ensures long-term support and a large pool of experienced developers.
Key integrations that strengthen Selenium with Java include:
Together, Selenium and Java offer a stable foundation for creating reliable, maintainable UI test suites that scale with application complexity.
To start your automation testing journey using Selenium with Java, the first step is to install and configure Selenium onto your local system. In this section of this article on Selenium with Java, I will guide you through the installation process step by step. You will also learn how to create a basic Selenium with Java project setup.
The installation process consists of the following steps.
Once the installation is complete, set the environment variables. The steps are as follows:
The environment variable setup is now complete. Open the command prompt and run the command java -version to verify that Java has been successfully installed in your system. Once verified, you can proceed to the next step: setting up your project.
You need to set up a project to write and store your test cases. Follow the steps below to create a new Selenium with Java project in Eclipse.
With your Selenium with Java project configured, you’re now ready to write and run your first test script.
To perform automated testing using Selenium with Java, you can also leverage Maven. Maven is one of the popular Java build tools that relies on POM.xml. If you are new to Maven, check out this Selenium Maven tutorial, which guides you through writing and running Selenium projects with Maven.
In this section, you will learn how to write and execute your first Selenium test using Java on your local machine. This will cover setting up your environment, creating a simple test script, and running it with a local browser.
Implementation
package LambdaTest;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
public class FirstTestScriptUsingWebDriver {
public static WebDriver driver = null;
@BeforeTest
public void setUp() throws Exception {
WebDriverManager.chromedriver().setup();
driver=new ChromeDriver();
}
@Test
public void firstTestCase() {
try {
System.out.println("Launching LambdaTest Sign In Page");
driver.get("https://accounts.lambdatest.com/register");
WebElement pageHeader= driver.findElement(By.xpath("//a[text()='Sign In']"));
pageHeader.click();
System.out.println("Clicked on the Sign In Button.");
} catch (Exception e) {
}
}
@AfterTest
public void closeBrowser() {
driver.close();
System.out.println("The driver has been closed.");
}
}

To import the required dependencies, you can use the below pom.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>LambdaTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0 </version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>
To run the above test case using Selenium with Java on a local grid, you can use the below testng.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="FirstTestScriptUsingWebDriverSuite">
<test name="FirstTestScriptUsingWebDriver" >
<classes>
<class name="LambdaTest.FirstTestScriptUsingWebDriver" >
</class>
</classes>
</test>
</suite>
Here is the code walkthrough of the executed test on a local grid using Selenium with Java.
Achieving consistent browser coverage in Selenium Java testing is tough due to flaky tests from dynamic content, timing issues, and varying environments. Cloud platforms like TestMu AI solve this with stable real-device infrastructure, reducing flakiness and enabling reliable, scalable testing with logs and debugging tools.
TestMu AI is a GenAI-native test execution platform that lets you perform both manual and Selenium Java automation testing using various test automation frameworks simultaneously across 3000+ browser and OS combinations. The platform enables parallel testing in Selenium, enhancing scalability and reducing test execution time with a simple setup and minimal configuration.
The same sign in scenario will be exeuting on cloud platfrom on parallel broswers will be using firefox , chrome, safari browser , all you need to do it making few changes to your exsisting testng.xml file as shown below:
<test name="WIN8TEST">
<parameter name="browser" value="firefox"/>
<parameter name="version" value="120.0"/>
<parameter name="platform" value="WIN8"/>
<classes>
<class name="FirstTestScriptUsingWebDriver"/>
</classes>
</test> <!-- Test -->
<test name="WIN10TEST">
<parameter name="browser" value="chrome"/>
<parameter name="version" value="121.0"/>
<parameter name="platform" value="WIN10"/>
<classes>
<class name="FirstTestScriptUsingWebDriver"/>
</classes>
</test> <!-- Test -->
<test name="MACTEST">
<parameter name="browser" value="safari"/>
<parameter name="version" value="11.0"/>
<parameter name="platform" value="macos 10.13"/>
<classes>
<class name="FirstTestScriptUsingWebDriver"/>
</classes>
</test> <!-- Test -->
Once you’ve added your parameters, update your test script to connect using the TestMu AI Grid URL:
gridURL = "@hub.lambdatest.com/wd/hub"
Next, configure the TestMu AI capabilities. Set your TestMu AI Username and Access Key as environment variables, and define automation capabilities such as browser, browser version, platform, and other settings as shown below:
ChromeOptions browserOptions = new ChromeOptions();
browserOptions.setPlatformName("Windows 10");
browserOptions.setBrowserVersion("121.0");
HashMap<String, Object> ltOptions = new HashMap<String, Object>();
ltOptions.put("username", "YOUR_LT_USERNAME");
ltOptions.put("accessKey", "YOUR_LT_ACCESS_KEY");
ltOptions.put("project", "Selenium with Java");
ltOptions.put("w3c", true);
ltOptions.put("plugin", "java-testNG");
browserOptions.setCapability("LT:Options", ltOptions);
You can generate the above Selenium Java capabilities from the TestMu AI Automation Capabilities Generator.
By running your Selenium Java tests on TestMu AI’s cloud infrastructure, you avoid the overhead of maintaining local setups. With support for parallel execution, it helps you scale efficiently, reduce test execution time, and accelerate your release cycles, all with minimal configuration.
To get started, refer to the documentation on Selenium Java testing with TestMu AI.
To run the tests for the cloned repository, run the following command.
mvn test -D suite=parallel.xml
Now, go to your TestMu AI Web Automation Dashboard to see your parallel test results.

Apart from the basic test scenarios, there are also advanced test cases you can perform using Selenium with Java that go beyond standard validations. These include automating complex, real-world interactions across modern web applications.
Selenium Java automation helps reduce manual effort, speed up execution, detect bugs early, improve coverage, and accelerate time to market.
However, test flakiness and incorrect approaches can make tests unreliable. Tools like HyperExecute by TestMu AI address these issues by reducing execution time and enabling faster debugging.
TestMu AI offers a SmartWait feature that runs a series of “actionability checks” on webpage elements before executing any action. These checks verify visibility, presence, and interactability to ensure elements are ready for actions like clicking or typing, resulting in more stable and reliable web automation tests.
Watch this video tutorial on Auto-healing in web automation by Anton Angelov (@angelovstanton), Co-founder & CTO of Automate The Planet, Forbes-featured test automation expert and best-selling author.
Selenium with Java is the most widely adopted test automation combination among QAs. In this tutorial, we explored how to start with Selenium Java automation testing and wrote our first test case.
On top of that, we also learned how to optimize test execution by leveraging parallel testing and other best practices to establish a reliable testing cycle. I hope this tutorial turns out to be beneficial. There’s much more to explore!
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance