Six Steps To Setup Selenium WebDriver Project in Eclipse

In this post, we will describe the easiest way to create and setup Selenium Webdriver project in Eclipse. We’ve covered the whole process in six main steps, starting from the required Software downloads for creating the Test Project. If you rightly follow the six steps, then it would be quite easy to write your first Selenium Test Script. You can use the below links to quickly browsing through the post.

Let’s first get aware of the pre-requisites to start our work.

Pre-requisite.

Steps to Download and Install Eclipse IDE.

  1. Before the start, please check if you have the Eclipse IDE installed on your system. If it’s not there on your system, then please install it from the following Link:
  2. For your note, there are different versions of Eclipse available like the Windows-32/64 bit, Linux, and MAC OS X operating systems. Hence, download the latest version of Eclipse that suits your system configuration.
  3. After the completion of the previous step, locate and start the “eclipse.exe” from the folder where you’d saved the Eclipse binary. And define a path for the “Workspace” which you’ll be using to setup Selenium Webdriver project.

In the subsequent sections, we will outline the necessary steps to setup Selenium Webdriver project. Please follow them one by one.

Setup Selenium WebDriver Project in Eclipse.

We’ve filtered and clearly presented the bare minimum steps required to set up a Selenium Webdriver project from the scratch. Every step is followed by visuals aids to let you easily imitate the process.

1) Add a New Java Project in Eclipse IDE.

Open Eclipse IDE, as described in above steps and select “Java Project” from the list of project types to create a new module.

This project will get automatically saved to the Workspace that you would have specified previously.

Setup Selenium WebDriver Project-1

Setup Selenium WebDriver Project-1

2) Enter the name for the project Eg-WebdriverDemoProject.

Setup Selenium WebDriver Project-2

Setup Selenium WebDriver Project-2

3) Create a New Package.

3.1- Right-click on the newly created project as New-> Package.

Setup Selenium WebDriver Project-3

Setup Selenium WebDriver Project-3

3.2- Give the name of the package, e.g. samplePackage and click on Finish.

Setup Selenium WebDriver Project-4

Setup Selenium WebDriver Project-4

4) Create a New Java Class.

4.1- Right-click on the newly created package to create a Java class as New->Class.

Setup Selenium WebDriver Project-5

Setup Selenium WebDriver Project-5

4.2- Give the name of the class file, e.g., –WebdriverDemo.

Select the checkbox for “public static void main (String[] args)” and click on Finish.

Setup Selenium WebDriver Project-6

Setup Selenium WebDriver Project-6

4.3- Newly created Java class file looks like this after successful creation.

Setup Selenium WebDriver Project-7

Setup Selenium WebDriver Project-7

5) Download the required jar files.

Before we can proceed with writing test scripts we have to download the following jars to let Selenium test scripts to execute.

5.1- Download Required Jar Files For Selenium WebDriver.

Download Selenium Webdriver jars (highlighted in red) from Selenium HQ Website (http://www.seleniumhq.org/download/), extract them and place them in “Jar Files” folder of “WebdriverDemoProject.”.

Setup Selenium WebDriver Project-8

Setup Selenium WebDriver Project-8

5.2- Download Apache POI API Jar Files.

5.2.1- It’s a favorite Java API of automation testers as it helps them read, write and create Microsoft Excel files. It also supports other file formats like DOC, DOCX, and PPT.

5.2.2- For downloading the Apache POI API Jar files go to the link (http://poi.apache.org/download.html) and click on “poi-bin-3.14-beta1-20151223.tar.gz” under the Binary Distribution table. It’ll take you to the mirror sites listing page to download the Apache POI API Jar files folder. Click on any mirror site link, download and extract the folder.

5.2.3- You will find the following JAR files inside the above folder. Copy all these software files and paste them in “Lib” folder of “WebdriverDemoProject “.

  1. poi-3.14-beta1-20151223.jar
  2. poi-ooxml-3.14-beta1-20151223.jar
  3. poi-ooxml-schemas-3.14-beta1-20151223.jar
  4. xmlbeans-2.3.0.jar (Inside the OOXML-lib folder)
  5. dom4j-1.6.1.jar (Inside the OOXML-lib folder)

(Note: Above jar files versions may vary In future. So, always use the latest version only.).

5.3- Download Apache log4j Jar File.

  • Log4j is used to generate logs during test execution. We can download Apache log4j files from link (http://logging.apache.org/log4j/1.2/download.html)
  • Click on the zip folder link, and it will take you to <zip> folder mirror links to download folder. Click on the mirror link to download the folder.
  • Extract the zip folder inside the folder and you’ll find the log4j 1.2.17.jar file. Copy this file and save it in the “Lib” folder of “WebdriverDemoProject”.

Now the “Lib” folder has all the required files. We will add more jar files in future if necessary.

6) Add Jar Files in Project Build Path.

6.1- Right-click on the project “WebdriverDemoProject”. Select Build Path->Configure Build Path.

Setup Selenium WebDriver Project-9

Setup Selenium WebDriver Project-9

6.2- Move to the Libraries tab and click on the “Add External JARs” option. It will open a pop-up for selecting the downloaded JARs.

Setup Selenium WebDriver Project-10

Setup Selenium WebDriver Project-10

6.3- Navigate to the “Lib” folder in which all the JARs are available. Select all of them (using Ctrl+A) and then click on the “Open” button. It’ll add all the JAR files in your project’s build path.

Setup Selenium WebDriver Project-11

Setup Selenium WebDriver Project-11

6.4- Now click on the “OK” switch to close the window.

So far, you’ve added all the jar files in the “WebdriverDemoProject” build path. And you are all settled to use the services in your project like the Apache POI, Webdriver, etc.

A new folder named “Referenced Libraries” gets created in “WebdriverDemoProject” and all libraries get added under this folder as shown in below image.

Setup Selenium WebDriver Project-12

Setup Selenium WebDriver Project-12

With this, you are all set to start writing your Selenium Webdriver test Scripts !!!

Eclipse IDE – Quick Tips.

  • Eclipse IDE brings in the auto-suggest feature which is quite handy in determining the Selenium Webdriver methods and their parameters. When you try to add the first statement to create a Webdriver object like the example is shown in the snapshot.
Setup Selenium WebDriver Project-13

Setup Selenium WebDriver Project-13

  • You may see some errors. To resolve them hover the mouse near the Webdriver line containing the issue, and you will see the Autosuggest option which suggests the possible fix for the errors. In this example importing the Webdriver file will remove the error so choose that option.
Setup Selenium WebDriver Project-14

Setup Selenium WebDriver Project-14

  • Again mouse hover on the Firefox Driver and from the Autosuggest options list, select the option to import the Firefox Driver.
Setup Selenium WebDriver Project-15

Setup Selenium WebDriver Project-15

Setup Selenium WebDriver Project-16

Setup Selenium WebDriver Project-16

So, that was about the Eclipse IDE’s Autosuggest option which is indeed a great help in writing the test scripts.

Footnote.

In this blog post, we’ve tried to showcase one of the quickest methods to setup Selenium Webdriver project in Eclipse. If any of you have any suggestion to optimize it further, then please share it with us in the comment box. Also please use the share icons around and help us to reach this post to a larger audience.

Best,

TechBeamers.

3 Comments

  1. kushal Reply
  2. Rosy Reply

Leave a Reply


*