Set Up Java, IntelliJ, Maven, and Your First Selenium Java Test

In Lesson 2, you met the Selenium ecosystem: WebDriver is the coding API, Selenium Manager helps with drivers, IDE can record actions, and Grid helps tests run at scale.

Today you will set up only the pieces needed for one local Java test. First install Java. Then use IntelliJ to create a Maven project. Maven downloads Selenium and TestNG. Finally, run one test against TestKru.

Think of it like setting up a kitchen before cooking. Java runs the recipe. IntelliJ is the workbench. Maven brings the ingredients. Selenium and TestNG are the instructions. Chrome is the thing your test will operate. Once this small lab works, later lessons can focus on browser automation instead of installation surprises.

ToolPlain-English job
JDK (Java)Compiles and runs your Java test code
IntelliJ IDEAThe editor where you write, run, and debug tests
MavenDownloads libraries (Selenium, TestNG) and builds the project
selenium-javaThe WebDriver API that controls the browser
TestNGRuns test methods and checks pass/fail assertions
Browser (Chrome)The real browser your test drives
Selenium ManagerHelps provide a matching browser driver when needed

You do not need Grid, IDE recording, or Docker for this lesson. The setup path is simple: install Java, create the Maven project, add two dependencies, then run one local Chrome test.

Selenium’s Java bindings need a JDK (Java Development Kit), not only a runtime that can start apps. A JDK includes the compiler (javac) and the tools you need to build projects. Official Selenium guidance requires Java 11 or newer for current Selenium 4 releases. The Selenium project’s own Java examples commonly compile with Java 17. Current TestNG releases also expect Java 11 or higher, so one modern JDK covers both.

Install a current long-term support (LTS) JDK such as 17, 21, or 25. This lesson’s installer and IntelliJ screenshots use JDK 21. Oracle’s download page may also show a JDK 25 tab. Either LTS release is fine for Selenium 4 and TestNG. The clicks are the same.

Download the JDK from Oracle Java downloads. You can also let IntelliJ fetch a JDK later (Project Structure → Download JDK). Download the JDK, not a JRE-only package. If your machine still has only Java 8, upgrade. Current Selenium Java is not built for Java 8.

Open the Oracle page and choose an LTS tab such as JDK 25:

select jdk 25

macOS supports Apple Silicon (ARM64 / aarch64) and Intel (x64). Choose the matching installer.

Not sure which Mac you have? Open the Apple menu → About This Mac. If the chip says Apple M1/M2/M3/M4, download ARM64. If it says Intel, download x64.

  1. Open Oracle Java downloads.
  2. Select an LTS release such as JDK 21, JDK 25, or 17.
  3. Open the macOS tab.
  4. Download the matching DMG Installer (ARM64 for Apple Silicon, x64 for Intel).
oracle download page
  1. Double-click the .dmg, then the .pkg installer.
  2. Click Continue, then Install, and enter your Mac password when asked.
  3. Close the installer, eject the DMG, and open a new Terminal window.
macOS JDK installer Continue screen
Figure: Example macOS JDK installer welcome screen. Click Continue, then Install. Exact wording can vary by JDK version.

Oracle installs the JDK under a path like /Library/Java/JavaVirtualMachines/jdk-<version>.jdk.

You need 64-bit Windows and administrator rights.

  1. Open Oracle Java downloads.
  2. Select an LTS release such as JDK 21 or JDK 25.
  3. Open the Windows tab.
  4. Download the x64 Installer (.exe).
windows download screen
  1. Run the installer as administrator, click through Next / Install, then reopen Command Prompt or PowerShell.
Windows JDK installer for Java SE Development Kit 21.0.2
Figure: Windows JDK InstallShield welcome screen for **Java SE Development Kit 21.0.2**. If you downloaded JDK 25, the version line will say 25.x instead. Click **Next**, then finish Install.

Recent Oracle JDKs usually install under C:\Program Files\Java\jdk-<version> and place java / javac on PATH.

java -version
javac -version
Terminal verifying java and javac versions
Figure: Successful check. Both `java -version` and `javac -version` should report 11 or higher.

If java works but javac is missing, install the full JDK. If IntelliJ sees the JDK but the terminal does not, IntelliJ can still run tests, but fix PATH before command-line Maven.

Most installs work after you open a new terminal. Use this section only if the verification commands above still fail.

macOS: run /usr/libexec/java_home -V, then add these lines to ~/.zshrc (change 21 to the JDK version you installed, such as 17 or 25), and open a new Terminal:

export JAVA_HOME=$(/usr/libexec/java_home -v 21)
export PATH="$JAVA_HOME/bin:$PATH"

If java_home -V lists only 17 or 25, use that number instead of 21. Windows: open Environment Variables, set JAVA_HOME to your JDK folder (for example C:\Program Files\Java\jdk-21), add %JAVA_HOME%\bin to Path, then open a new terminal.

Windows Environment Variables with JAVA_HOME
Figure: Example Windows Environment Variables dialog with JAVA_HOME pointing at the JDK folder. Use your real install path.

You can also let IntelliJ manage the JDK in Project Structure. Still verify javac once for terminal Maven later.

  1. Open https://www.jetbrains.com/idea/download/.
  2. Choose the installer for your operating system (macOS or Windows).
  3. Download the free/core IntelliJ IDEA build. If the page offers an Ultimate trial, you can skip the trial and use the free core features for this academy.
  4. Run the installer.
  5. On first launch, accept the default first-run choices unless you already know you want different plugins or a custom UI theme. Defaults are safe for Lesson 3.
  6. When IntelliJ finishes loading, you should see a welcome screen with New Project.

As of IntelliJ IDEA 2025.3, JetBrains ships a unified IntelliJ IDEA product. Core Java and Maven support remains free, and that free core is enough for this academy. An Ultimate trial is optional. Older Community Edition installs (2025.2 and earlier) also work for Java + Maven + TestNG.

IntelliJ helps you create Maven projects, sync pom.xml dependencies, run TestNG with a green play button, and catch compile errors before the browser starts. No paid plugins are required for Lesson 3.

Maven is your project’s shopping list. Instead of downloading Selenium jars by hand, you declare them in pom.xml, and Maven fetches matching versions from Maven Central. That is easier to share and update than loose jar files.

No, not for this lesson. IntelliJ includes a bundled Maven, so it can create and run this project without a separate Maven installation. You will need Maven on your system PATH only when you want to run mvn test from a terminal later.

  1. On the welcome screen, click New Project. If a project is already open, use File → New → Project.
  2. In the left list, select Java.
  3. Set the build system to Maven (not IntelliJ or Gradle).
  4. Under JDK, pick the JDK you installed earlier (17+ preferred). If the list is empty, click Add JDK / Download JDK and choose a modern LTS release.
  5. Name the project selenium-java-academy.
  6. Open Advanced Settings if that section is shown, then set GroupId to com.codekru and ArtifactId to selenium-java-academy.
  7. Click Create.
New intellij Project

groupId is like an organization namespace. artifactId is the project name Maven uses.

Wait until IntelliJ finishes indexing. You should see a Project tool window on the left with pom.xml and a src folder.

selenium-java-academy/
├── pom.xml
└── src/
    ├── main/java          (often empty for early tests)
    └── test/java          (put Selenium tests here)

Beginner Selenium tests belong under src/test/java. That is Maven’s standard test source folder.

Created a new project
Your pom.xml → Maven downloads jars → IntelliJ classpath ready → your test can import Selenium and TestNG

If IntelliJ shows a Maven sync banner after you edit pom.xml, accept it. Until sync finishes, imports may stay red even when the XML is correct.

Open pom.xml and use this starter. Versions move over time, so check Maven Central or the Selenium downloads page when you update later.

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.codekru</groupId>
    <artifactId>selenium-java-academy</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.release>17</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <selenium.version>4.46.0</selenium.version>
        <testng.version>7.12.0</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>
</project>
  • selenium-java: Official Selenium Java bindings. Selenium Manager ships with modern releases, so you do not add a separate Manager dependency.
  • testng: Annotations such as @Test and assertions such as Assert.assertTrue(...).
  • maven.compiler.release: Compile for Java 17.
  • <scope>test</scope> on TestNG: Normal for test libraries. It means TestNG is for tests, not for production app code.
  • Version properties: One place to bump Selenium or TestNG later.
  1. Save pom.xml.
  2. If IntelliJ shows a floating banner such as Load Maven Project or a reload icon on the Maven tool window, click it.
  3. You can also open View → Tool Windows → Maven, then click the refresh icon.
  4. Wait until sync finishes. In FirstSeleniumTest (after you create it), imports such as org.openqa.selenium.WebDriver and org.testng.annotations.Test should no longer stay red.
pom.xml file

At the time of writing, Selenium’s downloads page lists Java bindings 4.46.0 as stable.

Older tutorials required downloading chromedriver, matching it to Chrome, and setting webdriver.chrome.driver. That broke when Chrome auto-updated.

Since Selenium 4.6, Selenium Manager ships with Selenium. Official docs describe it as the built-in helper that can discover, download, and cache a compatible browser driver when one is not already available. Official docs still label it as Beta, but it is the default helper path for common local setups.

WebDriver driver = new ChromeDriver();

Behind that line: Selenium looks for a usable ChromeDriver, Selenium Manager can resolve one that matches your Chrome if needed, ChromeDriver starts a WebDriver session, and later commands travel to that session. The first fetch may need network access. Drivers are typically reused from a local cache (often ~/.cache/selenium on macOS/Linux).

Install Google Chrome for this lesson if it is not already on your machine. First-time setup is smoother when Chrome is already present.

  1. In the Project tool window, expand srctest.
  2. Right-click the java folder under test.
  3. Choose New → Package and name it com.codekru.academy.
  4. Right-click the new package and choose New → Java Class.
  5. Name the class FirstSeleniumTest and press Enter.
  6. Replace the generated class contents with the code below.
create a new test

Final path: src/test/java/com/codekru/academy/FirstSeleniumTest.java
Demo URL: https://testkru.com/Elements/TextFields (page title: Text Fields)

package com.codekru.academy;

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

public class FirstSeleniumTest {

    private WebDriver driver;

    @BeforeMethod
    public void setUp() {
        driver = new ChromeDriver();
    }

    @Test
    public void openTestKruTextFieldsPage() {
        driver.get("https://testkru.com/Elements/TextFields");

        String title = driver.getTitle();
        Assert.assertTrue(
                title.contains("Text Fields"),
                "Expected title to contain 'Text Fields' but was: " + title
        );
    }

    @AfterMethod
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
  1. package com.codekru.academy; places the class under src/test/java.
  2. Imports bring in WebDriver, ChromeDriver, TestNG annotations, and Assert.
  3. private WebDriver driver; holds the browser session.
  4. @BeforeMethod setUp() starts Chrome before each @Test. Selenium Manager can resolve ChromeDriver if needed.
  5. driver.get(...) opens the TestKru Text Fields page.
  6. driver.getTitle() reads the browser tab title.
  7. Assert.assertTrue(...) fails if the title does not contain Text Fields.
  8. @AfterMethod tearDown() calls quit() so the session closes even after a failure.

@BeforeMethod / @AfterMethod keep setup and cleanup consistent when you add more tests. Module 1 covers that lifecycle in more depth.

  1. java -version and javac -version both show 11+.
  2. IntelliJ Project SDK matches that JDK.
  3. Maven sync finished with no red dependency errors.
  4. Chrome is installed.
  5. The test class is under src/test/java.
  6. You can open https://testkru.com/Elements/TextFields in a normal browser.
  1. Save the file (Cmd+S on macOS or Ctrl+S on Windows).
  2. In the editor gutter next to the class name FirstSeleniumTest, or next to the openTestKruTextFieldsPage method, click the green run icon.
  3. Choose Run ‘FirstSeleniumTest’ / Run ‘openTestKruTextFieldsPage()’ using the TestNG runner.
  4. If IntelliJ offers more than one run configuration type, pick TestNG, not Application and not a plain main method runner.
  5. Watch the Run tool window at the bottom for pass/fail results.

Chrome opens, the Text Fields page loads, TestNG shows green/passed, and Chrome closes because quit() ran. If the assertion fails, confirm the exact URL and inspect driver.getTitle().

Optional: from the project root, mvn test also works if Maven is on your PATH. IntelliJ is enough for this lesson.

ProblemLikely causeWhat to try
javac not foundJDK missing or not on PATHInstall JDK 17+, reopen terminal
Red imports in IntelliJMaven not syncedReload Maven; check pom.xml
Browser never opensChrome missing or offline first runInstall Chrome; allow network for Selenium Manager
ChromeDriver version errorsOld manual driver on PATHPrefer Selenium Manager; remove stale driver paths
Chrome stays openForgot quit()Keep @AfterMethod cleanup
Wrong title assertionWrong URLUse the Text Fields URL above
TestNG run option missingWrong folder or missing dependencyPut class under src/test/java; re-sync Maven

Fix Java first, then Maven sync, then browser launch, then the assertion.

  • Install a JDK 11+ (17 recommended) on macOS or Windows.
  • Use IntelliJ IDEA (free core is enough) as your editor and runner.
  • Create a Maven project and declare selenium-java plus TestNG in pom.xml.
  • Let Selenium Manager help with browser drivers instead of hand-managing ChromeDriver.
  • Run a TestNG test that opens TestKru, asserts the title, and closes the browser with quit().

You now have a working Selenium Java lab. Everything ahead builds on this foundation.

Create a second test method in the same class (or a new class) that:

  1. Opens https://testkru.com instead of the Text Fields page.
  2. Asserts that driver.getTitle() equals TestKru (exact homepage title).
  3. Still uses @BeforeMethod / @AfterMethod so Chrome always closes.

Do not paste a finished solution here. Run it yourself and confirm both tests can pass one after another.

Continue practicing: Your First Selenium Script

Next lesson: WebDriver, WebElement, and the Test Lifecycle. You will go deeper into the objects behind today’s test: what a WebDriver session is, what a WebElement represents, and how setup and teardown stay reliable as tests grow.

1. Do I need Java 17 specifically? No. Current Selenium Java needs Java 11 or newer. Java 17 is a practical academy baseline because Selenium’s own examples commonly use it.

2. How do I install Java on macOS vs Windows? On macOS, download the matching ARM64 or x64 DMG and run the .pkg. On Windows, run the x64 .exe as administrator, then open a new terminal. Verify with java -version and javac -version.

3. Is IntelliJ Ultimate required? No. Free IntelliJ core features (and older Community Edition) are enough for Java, Maven, and TestNG in this course.

4. Why Maven instead of downloading jars manually? Maven records exact library versions in pom.xml and downloads them for you, which is easier to share and update than loose jar files.

5. Do I still need to install ChromeDriver? Usually not for beginners on Selenium 4.6+. Selenium Manager can resolve a matching driver when one is not already available.

6. Why put tests under src/test/java? That is Maven’s standard test source folder. Test-scoped dependencies like TestNG belong with code in that tree.

7. Why call quit() instead of only closing a window? quit() ends the WebDriver session and closes related windows. It is the normal cleanup for a finished test session.

8. Can I use Firefox instead of Chrome? Yes later. For this first setup, Chrome keeps troubleshooting simpler. Firefox would use FirefoxDriver with the same Maven Selenium dependency.

9. Which Selenium version should I use? Prefer a current stable selenium-java release from Selenium’s downloads page or Maven Central. This lesson’s sample uses 4.46.0.

10. Why TestNG and not JUnit? This academy standardizes on TestNG for annotations, assertions, and later features such as groups and data providers. Both can drive Selenium; we stay consistent with TestNG.

Liked the article? Share this on

Leave a Comment

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