Selenium Webdriver Setup

Selenium Webdriver with Java and Eclipse Setup

Following steps will guide you through setting up selenium webdriver on your machine-

Step.1. Configuring Java on machine
Download latest version of Java Development Kit(JDK) from here. Follow the steps mentioned to install JDK. We are installing JDK as it will be required for developing and running our automation scripts which are nothing but java programs.

Step.2. Download eclipse or any Java IDE of your choice
Download the latest version of the Java IDE you would like to use, for Eclipse the download link is http://www.eclipse.org/downloads/. Select the appropriate version of Eclipse depending on your system type- 34 bit or 64 bit.
Selenium
In order to check your system type- go to my computer and right click and select 'properties', under system section you will see a 'System type' parameter. This parameter will define your system type.
Selenium
Step.3. Download Selenium Webdriver jar from SeleniumHQ website
Go to SeleniumHQ website- http://docs.seleniumhq.org/download/ and under "Selenium Client & WebDriver Language Bindings" download the webdriver for java. Selenium
Unzip the package and place it on any directory as a library folder.

Step.4. Creating project and configuring selenium jars-

  • Launch eclipse.exe
  • Set your workspace to any location preferably other than C:(a workspace is a physical location where we store our project or group of related projects).
  • Now create a new project- File->New->Project...->Java->Java Project
  • Name you project and click Finish
  • Now you will see an src folder under your project. Under this we need to create a package-Right Click src->New->Package (Basically these packages are used to group together related classes). Name your package e.g. 'myTestPackage'
  • Inside this package create a new class and name it e.g. Test, your Test.java class will get created

Step.5. Adding selenium jars
Right Click your project on the left and click on properties. A "Properties for {project name}" dialog box will appear. Click on "Java Build Path" on the left and then click on Libraries tab on the right. In this tab click on "Add External Jars.." button.

Selenium

Now browse to the location where selenium libraries are placed(library folder Step#3). Make sure to add both the libraries-selenium-java-2.39.0.jar and selenium-java-2.39.0-srcs.jar along with the libraries present in libs folder(selenium-2.39.0\libs). The selected libraries will appear, click OK to add these libraries to your project. You can verify the same in the "Referenced Libraries" section under your project in the "Package Explorer" section on the left.

Step.6. Creating first selenium webdriver project
Time to test create your first selenium project. Just copy the below code in your Test.java file and make changes if your package and class names are different.

package myTestPackage;

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

public class Test{
  	public static void main(String[] args){
	//Create FirefoxDriver instance
        WebDriver driver = new FirefoxDriver();
       
        //driver.get will open www.artoftesting.com in firefox browser
        driver.get("http://www.artoftesting.com");
        System.out.println("Test Passed");
  }
}


To run the test, right click on Test.java file on the Package Explorer section, hover over "Run As" and select "Java Application". Firefox broswer will launch and open artoftesting.com.