Setting Up Selenium WebDriver in Java: A Step-by-Step Guide

View profile for prince saini

Software Tester | Manual Testing | Learning Automation (Selenium + Java) | Test Scenarios | Agile | Jira | SDLC | STLC | API Testing | Quality Focused

🌟 Day 13 of My 100 Days QA Challenge 🌟 Topic: Setting Up Selenium WebDriver – Step by Step 🧰 Getting your automation environment ready is the first real step toward writing tests. Here's how you can set up Selenium WebDriver in Java the right way: 🛠️ Step-by-Step Setup Guide 1. Add Selenium Dependency Use Maven/Gradle to include Selenium in your project. For Maven (pom.xml): <dependency>  <groupId>org.seleniumhq.selenium</groupId>  <artifactId>selenium-java</artifactId>  <version>4.35.0</version> <!-- latest stable version as of now -->   </dependency> You can check the current version at the Selenium Downloads page. Selenium 2. Manage WebDriver Binaries You need browser-specific drivers (ChromeDriver, GeckoDriver, etc.). Instead of manually downloading them, you can use WebDriverManager (Java library) to handle this for you automatically. import io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class WebDriverSetup {  public static void main(String[] args) {   WebDriverManager.chromedriver().setup(); // Automatically handles driver   WebDriver driver = new ChromeDriver();   driver.get("https://example.com");   System.out.println("Title: " + driver.getTitle());   driver.quit();  } } Note: With newer Selenium releases, Selenium Manager is being integrated to manage drivers internally. Selenium+1 3. Launching Browser & Running a Test Create WebDriver instance (Chrome, Firefox, etc.) Configure options (window size, headless mode, timeouts) Use driver.get(url) to navigate Perform actions (click, sendKeys, etc.) Assert results Close driver with driver.quit() 4. Best Practices & Tips Always use the latest matching versions of Selenium & WebDriverManager Clean driver cache if version mismatches arise (especially when browser updates) Use explicit waits instead of Thread.sleep() Run tests headlessly in CI environments Organize your setup logic (e.g. in a Base class) for reuse 👉 Tomorrow’s post: Day 14 – Writing First Selenium Script #100DaysQAChallenge #Selenium #AutomationTesting #WebDriverSetup #Java #WebDriverManager #SeleniumManager #TestAutomation #QualityAssurance #SoftwareTesting #TestingJourney #QALearning #ManualToAutomation #TestingTools #TesterLife #CodingForQA

To view or add a comment, sign in

Explore content categories