Getting started with Selenium WebDriver, Java and Eclipse IDE

In this blogpost, we will learn how to setup Selenium WebDriver with Eclipse IDE and Java and run the simple automation script.

Step 1 : Installing JDK (Java Development Kit) in the system. 

In this step, we will focus on installation of JDK in the system.

(Note : If you have JDK already installed in your system, jump to Step 2).

Visit http://www.oracle.com/technetwork/java/javase/downloads/index.html to download JDK.

jdk1

Click on Java Download button.

jdk2

 

Accept the Licence Agreement and download jdk version which suits your platform.

And the JDK setup will start downloading. Once it gets downloaded, complete the installation.

Step 2 : Installing Eclipse IDE in your system.

Go to http://www.eclipse.org/downloads/packages/ for downloading Eclipse IDE.

Eclipse-Installation-one.PNG

You can choose any of the Eclipse version from Release section(on left side bar).

We will download the Mars version of Eclipse, so click on Mars Packages from the Releases menu.

And now you can choose the Eclipse IDE for Java EE Developers as per your system configuration from the right side of the page (Windows 32-bit or 64-bit)

Eclipse-Installation-two.PNG

Click on DOWNLOAD button.

That’s it. Your system is now ready to develop and run simple Java application.

Step 3 : Downloading Selenium WebDriver JAR files.

Go to http://docs.seleniumhq.org/download/ to download Selenium client bindings for Java.

download-selenium-jars

Download Java Language binding (Version 2.53.0) or whichever is the latest.

The ZIP, containing all the JARs will be downloaded.

Step 4 : Moving JRE folder into Eclipse directory.

Now, after installing JDK and installing Eclipse and Selenium client bindings, before starting Eclipse, we need to move the JRE folder into Eclipse directory.

Go to the folder where you have installed JDK(C:\Program Files\Java).

Copy jre folder.

Paste the folder in Eclipse directory.  (C:\Program Files\eclipse).

Step 5: Configuring Eclipse workspace.

Go to Eclipse directory.

Double click on Eclipse.exe to launch Eclipse IDE.

Choose/ Browse the Workspace (The location where all the projects will be saved.) and Click OK button.

Step 6: Creating a simple project in Eclipse.

Now, it’s time to create a project in Eclipse.

Create a new project from File -> New -> Java Project.

create-project-in-eclipse.png

Give Project name, Select JRE version and click Finish button.

create-project-in-eclipse-twp.png

The Java project will be created in Eclipse.

create-project-in-eclipse-three

Now,  you need to add Selenium JARs to the build path of the project.

Right click on Project (in package explorer) -> Build path -> Configure build path.

add-jars-to-project-one.png

Click on Add External JARs button.

add-jars-to-project-two.png

Select all JAR files from downloaded zip file of Selenium bindings. Don’t forget to add JARs from lib folder. After adding all JARs, the libraries tab will look like this:

add-jars-to-project-three.png

Click Ok button. And hurrah, we are ready to write our first Selenium script. 🙂

Step 7: Creating simple Selenium script.

Right click on the src folder of project, and create a new class named SeleniumFirstScript.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SeleniumFirstScript {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get(“http://google.com”);
driver.manage().window().maximize();
System.out.println(driver.getTitle());
}
}

Run the program and you will get the title of Webpage in console.

Hope it helps you 🙂

Cheers 🙂

 

Advertisements