Selenium with Java · Getting Started

Set Up Java, Maven and Selenium

Lesson 2 of 9 · 10 min read

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

  1. Download a free JDK, version 17 or newer, for example Eclipse Temurin from adoptium.net.
  2. 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

  1. In IntelliJ choose New Project, then Maven (or Java with the Maven build system).
  2. Pick your JDK, name the project selenium-practice and 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
  1. What Is Selenium WebDriver?
  2. Set Up Java, Maven and Selenium
  3. Write Your First Selenium Test
  4. Selenium Locators: ID, CSS, XPath and More
  5. Clicks, Typing, Dropdowns, Alerts, Frames and Windows
  6. Waits in Selenium: Implicit, Explicit and Fluent
  7. TestNG for Selenium: Annotations, Assertions and Data
  8. Page Object Model in Selenium Java
  9. Selenium Framework Structure, Reports and CI