This Selenium Eclipse tutorial helps you start Selenium automation testing. It’s super easy for beginners. You’ll create a Selenium WebDriver project in Eclipse to run web tests. We use cool tools like Maven and ChromeDriver, popular in 2025. Follow these simple steps for a Selenium WebDriver setup. It’s fun and clear!
- Checklist for Your First Selenium WebDriver Project
- Setup Your First Selenium WebDriver Project
- Step 1: Get Your Tools Ready
- Step 2: Make a Maven Project in Eclipse
- Step 3: Add Selenium and ChromeDriver
- Step 4: Create a Test Class
- Step 5: Run Your Selenium Test
- Step 6: Fix Errors with Autosuggest
- What To Do Next
- Your First Selenium WebDriver Project: Key Takeaways
Checklist for Your First Selenium WebDriver Project
- Install Eclipse and Java for Selenium testing.
- Make a project with Maven for easy setup.
- Add Selenium and ChromeDriver tools.
- Write a simple test script for your project.
- Run your first web test with Selenium.
Setup Your First Selenium WebDriver Project
Selenium WebDriver runs web browsers for testing. It clicks buttons or fills forms on websites. Setting up a project in Eclipse makes tests super easy. You keep code and tools in one place. This saves time and makes tests clear and nice.
Step 1: Get Your Tools Ready
You need Eclipse, Java, and Maven for Selenium automation testing. Let’s set them up fast.
- Install Eclipse:
- Visit the Eclipse website.
- Get the latest Eclipse IDE for Java Developers (2025 version or newer).
- Install it on your computer (Windows, macOS, or Linux). Follow the easy steps.
- Cause and Effect: Install Eclipse. It lets you write nice test code.
- Install Java:
- Go to the Oracle website for Java.
- Pick JDK 17 or newer. Selenium needs it to work.
- Install it. Set the JAVA_HOME path (look up a guide for your system).
- Cause and Effect: Add Java. It runs your Selenium test code.
- Install Maven:
- Download Maven from the Maven website.
- Follow the setup guide for your computer. Add Maven to your PATH.
- Cause and Effect: Install Maven. It gets Selenium tools for you.
Step 2: Make a Maven Project in Eclipse
Maven makes adding Selenium tools super simple. Let’s create a project now.
- Start a New Project:
- Open Eclipse. Click File > New > Project.
- Pick Maven > Maven Project. Click “Next.”
- Check “Create a simple project.” Click “Next.”
- Cause and Effect: Start a Maven project. It holds your test code nicely.
- Set Project Names:
- Enter Group Id: com.example.
- Enter Artifact Id: SeleniumTest.
- Click “Finish.” Eclipse makes your project folder.
- Cause and Effect: Name your project. It creates a place for your code.
If you use Firefox as your primary browser, try our quick guide on Selenium testing with Firefox.
Step 3: Add Selenium and ChromeDriver
Maven adds Selenium and ChromeDriver easily. Update the pom.xml file.
- Open pom.xml:
- Find pom.xml in your “SeleniumTest” project. Double-click it in Eclipse.
- Cause and Effect: Open pom.xml. It lists your project’s tools.
- Add Tools:
- Replace the pom.xml content with this:
<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>com.example</groupId>
<artifactId>SeleniumTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.18.1</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.6.2</version>
</dependency>
</dependencies>
</project>
- Cause and Effect: Add this code. Maven gets Selenium and WebDriverManager for you.
Tool Tip: Save pom.xml. Eclipse shows “Building project.” Wait for it to finish.
Step 4: Create a Test Class
Now, write a simple test to check your Selenium WebDriver setup.
- Make a Package:
- Right-click src/main/java in “SeleniumTest.” Choose New > Package.
- Name it com.example.tests. Click “Finish.”
- Cause and Effect: Create a package. It keeps your test code organized.
- Add a Test Class:
- Right-click the com.example.tests package. Choose New > Class.
- Name it FirstTest. Check “public static void main(String[] args).” Click “Finish.”
- Cause and Effect: Add this class. It runs your Selenium test.
- Write the Test Code:
- Open “FirstTest.java.” Replace its code with this:
package com.example.tests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.time.Duration;
public class FirstTest {
public static void main(String[] args) {
// Set up Chrome browser
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
// Open a website
driver.get("https://www.saucedemo.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
// Check the page title
String title = driver.getTitle();
if (title.contains("Swag Labs")) {
System.out.println("Test passed! Title is: " + title);
} else {
System.out.println("Test failed! Title is: " + title);
}
// Close browser
driver.quit();
}
}
Code Explanation
- Imports: Add tools for Selenium, ChromeDriver, and time handling. They run your test.
- WebDriverManager: Sets up ChromeDriver. It opens Chrome easily.
- Selenium Actions: Opens saucedemo.com. Makes the window big. Waits 10 seconds for the page.
- Check Result: Gets the page title. If it has “Swag Labs,” the test passes. If not, it fails.
- Cause and Effect: Run this code. It checks if the website loads correctly.
Step 5: Run Your Selenium Test
Test your setup to see Selenium WebDriver work.
- Check Your Setup:
- Make sure pom.xml has Selenium and WebDriverManager.
- Confirm “FirstTest.java” is in the com.example.tests package.
- Cause and Effect: Check these. They make your test run smoothly.
- Run the Test:
- Right-click “FirstTest.java” in Eclipse. Choose Run As > Java Application.
- Chrome opens. It visits saucedemo.com and checks the title.
- The console shows “Test passed!” or “Test failed!” with the page title.
- Cause and Effect: Run the test. It shows if your setup works.
Step 6: Fix Errors with Autosuggest
Eclipse makes fixing code errors super easy.
- Use Autosuggest:
- See red lines under code? Hover your mouse over them.
- Eclipse shows fix options, like adding imports. Click the right one (e.g., “Import WebDriver”).
- Cause and Effect: Use autosuggest. It fixes errors quickly.
Try some cool stuff with Selenium – Switch to Close the Window
What To Do Next
- Write more tests. Try clicking buttons or filling forms.
- Learn more. Visit Selenium Documentation for cool testing tips.
- Practice. Add new test classes to your project.
- Tool Tip: Use Eclipse’s “Debug” mode. It finds code problems fast.
Your First Selenium WebDriver Project: Key Takeaways
Great work! You set up a Selenium WebDriver project in Eclipse. You learned to:
- Install Eclipse, Java, and Maven for testing.
- Create a Maven project for Selenium automation.
- Add Selenium and ChromeDriver tools.
- Write and run a simple web test.
Got questions? Comment below. Share this Selenium Eclipse tutorial on LinkedIn or Twitter. Help others learn Selenium automation testing!
Happy testing,
TechBeamers