How to Configure Selenium in Eclipse IDE

In this article I will walk through the steps required to configure Selenium in Eclipse IDE from Scratch. I hope you might have already have installed Java and would have Eclipse IDE as well.
If Java is not installed on your system, then please Download & install the latest Java JDK from here.
http://www.oracle.com/technetwork/java/javase/downloads/index.html
clip_image002
Double Click on the JDK installer and follow the on screen instructions to get the JDK installed on your machine.
You can download the latest Eclipse IDE from here (http://www.eclipse.org/downloads/). Here in this tutorial, I have used Eclipse Mars 2 IDE to showcase configuring Selenium in Eclipse IDE.
Now download Selenium from here (http://docs.seleniumhq.org/download/). You will have to download both Selenium Standalone Server & Java Client driver (Selenium Client & WebDriver Language Bindings) as highlighted below.
clip_image006
Selenium Standalone Server is required to run Remote Selenium Web Drivers. In order to create scripts that interact with the Selenium Server (Selenium RC, Selenium Remote WebDriver) or create local Selenium WebDriver scripts, will have to use language-specific client drivers.
Once the required files are downloaded. Extract the downloaded selenium-java-2.53.0 Zip File to a folder as shown below.
clip_image008
Along with the Selenium Standalone Server & Selenium Java Jars the following Jar files which is the available in the extracted libs folder (Shown Below) is also required.
clip_image010
Now that we have installed Java, Downloaded required Selenium Jars & Eclipse IDE, let us look at how to configure Selenium in Eclipse.
Launch Eclipse & Choose a workspace name as shown below.
clip_image012
Once the Eclipse IDE is open, click on File à New Project à Java Project as shown below.
clip_image014
In the Create New Project window, provide a Project Name and click on Next button.
clip_image016
Keep the default settings as is and click on Finish Button.
clip_image018
Now let’s go ahead and create a Libs folder in the created project. Right click on the Package Explorer and choose New à Folder.
clip_image020
clip_image022
Now navigate to the Selenium Demo Project location through Windows File Explorer and copy all the jars mentioned above including Selenium Standalone Server, Selenium-Java and other jars into the libs folder as shown below.
clip_image024
Refresh your workspace in Eclipse IDE. All the jars added should appear in the IDE.
Let us create a Class and write a small piece of Code to Configure & execute a simple Selenium Script as a Java Application.
Right Click on the Project à New­­ à Class
Provide a Package Name & Class Name as shown below and click on Finish Button.
clip_image026
Below is a sample Java Code to invoke Google.com through Firefox Browser.
clip_image028
As you can see in the above code there are some unresolved errors. Let us try to fix them now.
Right click on your Project in the Package Explorer and choose Configure à Configure Build Path option as shown below.
clip_image030
Click on Libraries Tab and select Add Jars.
clip_image032
Navigate to the Project Folder, select all jars from the Libs folder and click on OK button to add the Jars.
clip_image034
clip_image036
Then Click on OK Button. Now click on the errors in the Editor window and import the required packages. Finally your code should be error free as shown below.
clip_image038
Now right Click on the Project / Java File and choose Run As àJava Application to execute the Script.
clip_image040
The Code should execute and you should be able to view the Google Page launched through Firefox Browser.
clip_image042
In this series, Hope I have provided as much as detail possible and you should be able to simply follow the above steps to configure Selenium in Eclipse IDE and run your First Selenium Script.

Keep watching this space for more articles on Selenium. Until then Happy Testing..!!

How to Configure Selenium in Eclipse IDE How to Configure Selenium in Eclipse IDE Reviewed by Suntaragali The Smart Techie on May 20, 2016 Rating: 5

No comments: