9b. WebDriver – Set Up in Eclipse

Welcome to our first explore-along post of WebDriver series. It is recommended that you follow closely and work along to make the set up process all the more simple!

Pre-requisites:

  1. Have an active internet connection.
  2. Download and install Java SE Development Kit (JDK) on your system. (http://www.oracle.com/technetwork/java/javase/downloads/index.html)
  3. Download Eclipse IDE. Installation isn’t required. Just extract all the contents to a folder and double click on the executable file. (http://www.eclipse.org/downloads/)

Time to follow 3 steps for setting up the environment,

Step 1:

Go to http://www.seleniumhq.org/download/. Under “Selenium Client & WebDriver Language Bindings” section, click on the download link against the language ‘Java’. (Please note that the version number that you are seeing might be different from the one in the snapshot here as 3.0.0-beta2 is the latest when this post is created.)

WebDriver Download

Step 2:

Extract the downloaded files to required location on your system. Switch over to Eclipse and choose the desired workspace directory.

Create a new Java Project as follows, File -> new -> Java Project. I have named my project as ‘WebDriver Tests’.

Step 3:

Right click on the created project. Choose ‘Build Path’ -> ‘Configure Build Path…’

Set up in eclipse

Now there are TWO WAYS to add external JARs to our project.

Method 1:

Make sure the ‘libraries’ tab is selected. Click on “Add External JARs…” button. A ‘JAR Selection’ window will open. Browse to the location where the files from seleniumhq.org site (Selenium Client and WebDriver Language Bindings) were downloaded and extracted.

Make sure that you select all the files with type, ‘Executable Jar File’.  Currently I have one file in ‘selenium-java-3.0.0-beta2’ folder and 16 files in selenium-java-3.0.0-beta2\lib folder.

Click ‘Open’ to add them to the Libraries tab.

set up - adding jars

Method 2:

This is really handy when you are adding numerous external JAR files for various purposes such as, WebDriver, JUnit, Ant etc. If method 1 is followed, then it might become very difficult to differentiate the JARs added for each purpose. Whereas in method 2, we will be creating a separate folder and name accordingly for easy identification and documentation purposes.

Make sure the ‘libraries’ tab is selected. Click, Add Library… -> User Library -> Next.

set up - user library

Now click on ‘User Libraries…’ A new window will open. Click, New… -> specify the folder’s name -> OK.

User library custom name

Click on “Add External JARs…” button. A ‘JAR Selection’ window will open. Browse to the location where the files from seleniumhq.org site (Selenium Client and WebDriver Language Bindings) were downloaded and extracted.

Make sure that you select all the files with type, ‘Executable Jar File’.  Currently I have one file in ‘selenium-java-3.0.0-beta2’ folder and 16 files in selenium-java-3.0.0-beta2\lib folder.

Click ‘Open’ to add them to the created folder under ‘User Libraries’ window. Click ‘OK’ and now you will see the user library with a checkbox in the ‘Add Library’ window. Make sure the checkbox is checked and click ‘Finish’. The created user library will all the added external JARs will now be available in the Libraries tab of the project’s properties window.

set up - jars

Once ‘OK’ button is clicked, newly added JARs will be visible under the project in the ‘Package Explorer’ pane.

Eclipse package explorer

Sticky Note: (This just tells you to make a NOTE)

 This setup works perfectly well with Selenium 2 versions (I have been using them from quite some time and it’s all fine). But if you are using Selenium 3 beta releases as I have shown in the above screenshots, then a few additional steps are to be followed.

  • Download “geckodriver.exe” from ‘https://github.com/mozilla/geckodriver/releases’.

set up - gecko driver

  • While writing test scripts, make sure you include the below line (Also make sure the Firefox browser version in your system is 48+),
System.setProperty("webdriver.gecko.driver", "<path_to_geckodriver.exe>");

Guess what?! You are all set for now and very soon we will be creating and running our first test script by launching Firefox browser.

See you again in another post. Have a nice day!

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.