Set Up Java, Maven and Selenium
You need three things: a JDK (to run Java), an IDE (to write code) and Maven (to download libraries like Selenium). This takes about 15 minutes.
Step 1: Install the JDK
- Download a free JDK, version 17 or newer, for example Eclipse Temurin from adoptium.net.
- Install it, then open a terminal and run
java -version. You should see the version number.
Step 2: Install IntelliJ IDEA
Download IntelliJ IDEA Community Edition (free). It includes Maven, so you do not need to install Maven separately.
Step 3: Create a Maven project
- In IntelliJ choose New Project, then Maven (or Java with the Maven build system).
- Pick your JDK, name the project
selenium-practiceand click Create.
Maven creates this structure. Tests always go in src/test/java.
selenium-practice/
pom.xml
src/
main/java/
test/java/
Step 4: Add Selenium and TestNG
Open pom.xml and add these dependencies inside <project>. Check Maven Central for the newest versions.
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.27.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Click the small Maven "reload" icon. IntelliJ downloads the libraries.
Step 5: Check it works
Create src/test/java/SmokeTest.java:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class SmokeTest {
@Test
public void browserOpens() {
WebDriver driver = new ChromeDriver();
driver.get("https://testqualityhub.com/practice/login/");
System.out.println(driver.getTitle());
driver.quit();
}
}
Click the green arrow next to the method. Chrome opens, loads the page, prints the title and closes. If it works, your setup is done.
Common problems: "cannot find symbol ChromeDriver" means Maven did not reload. "session not created" usually means Chrome is not installed or is very old.
All 9 lessons in Selenium with Java
- What Is Selenium WebDriver?
- Set Up Java, Maven and Selenium
- Write Your First Selenium Test
- Selenium Locators: ID, CSS, XPath and More
- Clicks, Typing, Dropdowns, Alerts, Frames and Windows
- Waits in Selenium: Implicit, Explicit and Fluent
- TestNG for Selenium: Annotations, Assertions and Data
- Page Object Model in Selenium Java
- Selenium Framework Structure, Reports and CI