Introduction to Selenium
Selenium WebDriver Basics
WebDriver Commands
Synchronization in Selenium
Working with Different Browsers
Setting up WebDriver for different browsers
Handling Advanced User Interactions
Page Object Model (POM)
Introduction to POM
TestNG Framework
Creating and Running TestNG Tests

Here’s a step-by-step guide to set up your environment for Java development using Eclipse IDE and Selenium WebDriver.

Step 1: Install Java Development Kit (JDK)

1. Download JDK:

2. Install JDK:

  • Run the installer and follow the instructions to install JDK.
  • Set the JAVA_HOME environment variable to point to the JDK installation directory.
  • Add the bin directory of the JDK to the PATH environment variable.

3. Verify Installation:

  • Open a command prompt (Windows) or terminal (Mac/Linux) and type:
				
					java -version
javac -version

				
			
  • Ensure the versions match the installed JDK.

Step 2: Install Eclipse IDE

1. Download Eclipse:

2. Install Eclipse:

  • Extract the downloaded package.
  • Run the’ eclipse‘ executable to start the IDE.

Step 3: Setup Selenium WebDriver

1. Download Selenium WebDriver:

2. Setup a New Java Project in Eclipse:

  • Open Eclipse.
  • Go to File > New > Java Project.
  • Enter the project name and click Finish.

3. Add Selenium WebDriver to the Project:

  • Right-click on the project in the Project Explorer.
  • Select Build Path > Add External Archives.
  • Navigate to the location where you downloaded the Selenium Java client library and add the JAR files.

4. Download WebDriver Executable:

  • Go to the Selenium downloads page.
  • Download the WebDriver executable (e.g., ChromeDriver for Chrome, GeckoDriver for Firefox) suitable for your browser.
  • Add the path to the WebDriver executable to your system’s PATH environment variable or set it programmatically in your tests.

Step 4: Write a Simple Selenium Test

1. Create a New Class:

  • Right-click on the src folder in your project.
  • Select New > Class.
  • Name the class (e.g., GoogleSearchTest) and click Finish.

2. Write the Test Code:

				
					import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearchTest {
    public static void main(String[] args) {
        // Set the path to the WebDriver executable
        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

        // Create a new instance of the Chrome driver
        WebDriver driver = new ChromeDriver();

        // Launch the Google website
        driver.get("https://www.google.com");

        // Find the search box using its name attribute
        WebElement searchBox = driver.findElement(By.name("q"));

        // Enter a search term
        searchBox.sendKeys("Selenium WebDriver");

        // Submit the search form
        searchBox.submit();

        // Print the title of the page
        System.out.println("Page title is: " + driver.getTitle());

        // Close the browser
        driver.quit();
    }
}

				
			

3. Run the Test:

  • Right-click on the Java file containing your test.
  • Select ‘Run As > Java Application‘.

This simple test will open a Chrome browser, navigate to Google, perform a search for “Selenium WebDriver”, print the page title, and close the browser.

Additional Tips:

  • WebDriver Manager: To avoid manual setup of WebDriver executables, consider using WebDriverManager. Add the following dependency to your project (if using Maven):
				
					<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>4.4.3</version>
</dependency>

				
			
  • Then update your test code to:
				
					import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearchTest {
    public static void main(String[] args) {
        // Setup WebDriver using WebDriverManager
        WebDriverManager.chromedriver().setup();

        // Create a new instance of the Chrome driver
        WebDriver driver = new ChromeDriver();

        // Rest of the test code...
    }
}

				
			
  • Browser Drivers: Make sure the WebDriver executable version matches your browser version.
Scroll to Top