In this post, we will describe the easiest way to create and setup Selenium Webdriver project using the Eclipse IDE.
We’ve covered the whole process in six main steps, starting from the required Software downloads for creating the Test Project.
If you’ll follow this tutorial correctly, then it would be quite easy to write your first Selenium Test Script.
This tutorial covers the following topics in-depth.
- How to Install Eclipse IDE?
- How to create your first Webdriver project in eclipse?
- How to download Jar files required for Selenium Webdriver?
- How to include Jar files in a project?
- Eclipse IDE – Quick Tips
Let’s first get aware of the pre-requisites to start our work.
- 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:
- 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.
- 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.
Your First Selenium WebDriver Project in Eclipse
We’ve given the bare minimum steps required to set up a Selenium Webdriver project from scratch. Follow Eclipse IDE images for proper guidance.
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.
2) Enter the name of the project Eg-WebdriverDemoProject.
3) Create a New Package.
3.1- Right-click on the newly created project as New-> Package.
3.2- Give the name of the package, e.g. “<samplePackage>” and click on Finish.
4) Create a New Java Class.
4.1- Right-click on the newly created package to create a Java class as New->Class.
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.
4.3- Newly created Java class file looks like this after successful creation.
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.
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.”.
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.”
- XMLbeans-2.3.0.jar (Inside the OOXML-lib folder)
- dom4j-1.6.1.jar (Inside the OOXML-lib folder)
(Note: Above jar files could upgrade 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 the 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.1- Right-click on the project “WebdriverDemoProject.” Select Build Path->Configure Build Path.
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.
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.
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.
With this, you are all set to start writing your Selenium Webdriver test Scripts !!!
- Eclipse IDE brings in the auto-suggest feature which is quite handy in determining the Selenium Webdriver methods and their parameters. When you add the first line of code to create a Webdriver object like the example is shown in the snapshot.
- 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 to remove the mistake so choose that option.
- Again mouse hovers on the Firefox Driver and from the Autosuggest options list, select the option to import the Firefox Driver.
So, that was about the Eclipse IDE’s Autosuggest option which is indeed a great help in writing the test scripts.
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 broader audience.