Setup Selenium Java
Project - Java, Maven,
IntelliJ IDEA
(Quick Guide Setup)
Prepared by :-
Kushal Parikh
Driving Quality Through Automation
Checkout my topmate - https://topmate.io/kushalparikh11
● Setting up Java & Maven Environment Variables
■ 1️⃣ Install & Configure Java
Step 1: Check if Java is installed using Command Line CMD:
java -version
Step 2: If not installed, download and install Java:
● Windows/Mac/Linux: Download JDK
Step 3: Set environment variables:
● Windows:
1. Go to System Properties → Advanced → Environment Variables
2. Add JAVA_HOME = C:\Program Files\Java\jdk-XX
3. Add JAVA_HOME\bin to Path
Follow me on LinkedIn - https://www.linkedin.com/in/kushalparikh11/
Mac/Linux: Add to ~/.bashrc or ~/.zshrc:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-
XX.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
Step 4: Verify setup - Open Command Line CMD
java -version
Checkout my topmate - https://topmate.io/kushalparikh11
■ 2️⃣ Install & Configure IntelliJ IDEA
Step 1: Download and install IntelliJ IDEA (Community Edition is free).
Step 2: Install Maven Plugin (comes pre-installed in IntelliJ).
■ 3️⃣ Install & Configure Maven
Step 1: Check if Maven is installed:
mvn -version
Step 2: If not installed, download & install:
Download Apache Maven
Step 3: Set environment variables:
● Windows:
1. Add MAVEN_HOME = C:\apache-maven-XX
2. Add MAVEN_HOME\bin to Path
Note - Already shown maven variables in above screenshots for
Java environments
Step 4: Verify setup:
mvn -version
Follow me on LinkedIn - https://www.linkedin.com/in/kushalparikh11/
■
● Selenium Java Project Setup - Create Project
■ 1️⃣ Create a Maven Project in IntelliJ IDEA
Step 1: Open IntelliJ IDEA → New Project
Step 2: Select Maven, Enter your project name & click on Finish button
Checkout my topmate - https://topmate.io/kushalparikh11
Follow me on LinkedIn - https://www.linkedin.com/in/kushalparikh11/
■ 2️⃣ Add Dependencies in pom.xml
Step 1: Open pom.xml and add Selenium dependency from below link : -
Link - https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.28.1</version>
</dependency>
</dependencies>
Checkout my topmate - https://topmate.io/kushalparikh11
Click on Maven Load Icon to load the changes !
Step 2: Update project dependencies:
mvn clean install
Follow me on LinkedIn - https://www.linkedin.com/in/kushalparikh11/
■ 3️⃣ Create Your First Selenium Test
Step 1: In src/test/java, create a new Java class - SeleniumDemoTest.java
Step 2: Add the following Selenium test script:
import org.openqa.selenium.WebDriver;
Checkout my topmate - https://topmate.io/kushalparikh11
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumDemoTest {
public static void main(String[] args){
// Initialize WebDriver
WebDriver driver = new ChromeDriver();
// Maximize browser window
driver.manage().window().maximize();
// Open Google
driver.get("https://www.google.com");
// Print Page Title
System.out.println("Page Title: " + driver.getTitle());
// Close the browser
driver.quit();
}
}
Follow me on LinkedIn - https://www.linkedin.com/in/kushalparikh11/
5️⃣ Run the Selenium Test
Step 1: Right-click on SeleniumDemoTest.java
Checkout my topmate - https://topmate.io/kushalparikh11
Step 2: The browser should launch and open Google.
■ Your Selenium Java Maven Project is Ready!
Now you have a fully configured Selenium Java Test Automation Setup using Java,
Maven & IntelliJ IDEA!
Follow me on LinkedIn - https://www.linkedin.com/in/kushalparikh11/