Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Install Selenium Webdriver with Eclipse and Java

To use Selenium WebDriver with Java JUnit or TestNG, you need to install a Java Development IDE. There are many options available like : Eclipse and IntellJ. Here I explain how to download and install Selenium WebDriver with Eclipse and Java step by step.

Step 1: download and install Java in your system.

You need to install JDK (Java development kit) in your system. Java may have been installed on your system. Refer to the article "Test Java for Selenium WebDriver" for more information.

Step 2: download and install Eclipse

download Eclipse for Java developers, extract the zip file, and save it in any drive. Download URL is : http://www.eclipse.org/downloads/index.php

Please remember that depending on the 32 or 64 bit on your PC, you need to install related package.

 

Step 3: download WebDriver Java Client driver.

Selenium WebDriver supports many languages and each language has its own client driver. Since we are using Java with Eclipse, we need to download "webdriver Java client".  Click this link to go to the download page (http://docs.seleniumhq.org/download/).  On the page, click on "Download" link of Java client driver as shown in the image below.

Downloaded 'webDriver Java client driver' will be in zip format. Extract and save it in your system at path C:\selenium-2.39.0. There will be 'libs' folder, 2 jar files and change log in unzipped folder as shown in the image below. We will use all these files for configuring webdriver in eclipse.

Step 4: Start Eclipse and configure it with Selenium WebDriver

Navigate to the folder where you upzipped the Eclipse package. Double click on 'eclipse.exe' to start eclipse. First time when you start eclipse, it will ask you to select your workspace where your work will be stored as shown in bellow image. By default, Eclipse will create a workspace folder under "My Documents".  You can use default folder or create a new folder like "TestAutomationWorkspace" and select it as your workspace. You can change it later on from 'Switch Workspace' under 'file' menu of eclipse. If you prefer this folder as your default workspace, check the option "Use this as the default and do not ask again".

After selecting workspace folder, Eclipse will be open. Now you can create a new Java test project.

Step 5: Create a new Project

Let's create a test project for testing Selenium Master Login module. Open Eclipse, open File menu, click on New and then select "Java Project". In the Project name , enter "SeleniumMasterLoginModuleTest" and click on the Finish button.

Now, your new created project "SeleniumMasterLoginModuleTest" will display in eclipse project explorer as shown on the image below.

Create a new package

Expand the "SeleniumMasterLoginModuleTest" project , and Right click on the src folder and select select New > Package.

 

Enter "com.seleniummaster.loginmodule" as package name.

Create a new JUnit Class

Right click on package 'com.seleniummaster.loginmodule' and select New > JUnit Test Case and set class name = 'LoginTest' and click on Finish button. It will add new JUnit test class 'LoginTest' under package 'com.seleniummaster.loginmodule'. Eclipse will prompt to add JUnit4 on the build path. Click OK.

Now your project window will look like this image below.

Add external Selenium jar files to java build path

  • Right click on the project "SeleniumMasterLoginModuleTest" and then select "Build Path" in the menu, and then click on "Configure Build Path".
  • In the Java Build Path window, Navigate to Libraries tab.  click on "Add External JARS" button > select both .jar files from C:\Selenium2.39.0 folder.
  • Click on "Add External JARS" button > select all .jar files from C:\Selenium2.39.0\libs folder. (This step is optional, Eclipse normally includes common used Java Jar files.

Now your SeleniumMasterLoginModule's properties dialogue will looks like bellow.

That's all about configuration of WebDriver with eclipse. Now you are ready to write your test in eclipse and run it in WebDriver.