How to configure Selenium in Eclipse
Tags: selenium, testing, eclipse, java
Published: 2022-02-04 13:15:23

Managing user experience is pivotal for software development. Test automation enables user preferences and convenience to remain at the center of the development process while saving time and effort. That is why comprehensive automation testing has become necessary to retain customers and meet their expectations. With significantly shorter time frames for development, Selenium Testing, in particular, has become an integral part of the development to facilitate automated testing of web applications. 

Selenium is the most popular automated tool in existence today. [59.5%](https://www.selenium.dev/blog/2021/selenium-survey-results/) of people consider Selenium for Cross Browser Testing because of the robustness and flexibility it offers by supporting multiple languages like Java, C#, Python, Perl, Ruby, etc. However, a majority (67%) of the Selenium users prefer Java as their language for [Selenium Testing](https://www.browserstack.com/selenium).

This article discusses [how to configure Selenium in Eclipse](https://www.browserstack.com/guide/how-to-setup-selenium-in-eclipse) to use Selenium for Java.

## Prerequisites for configuring Selenium in Eclipse

### - [Install Java](https://www.oracle.com/java/technologies/javase-jdk16-downloads.html)

Download Java SE Development Kit 16.0.2 according to the Windows, Linux, or macOS platform being used.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgppzmis0umfgdw6jjkz.png)

Run the JDK Installer by double-clicking on the file name in the download location and following the instructions on the instruction wizard. Alternatively, silently install JDK by entering the following command:

`jdk.exe /s `

### - [Install Eclipse IDE](https://www.eclipse.org/downloads/)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x10xj34f5vmtjjcotu7v.png)

### - [Install Selenium](https://www.selenium.dev/downloads/)
Download and Install Selenium to be set up in Eclipse.

### - Install Browser Driver
For [Cross Browser Testing](https://www.browserstack.com/cross-browser-testing), download the relevant Browser Driver – [ChromeDriver](https://chromedriver.chromium.org/) (for Chrome), [GeckoDriver](https://github.com/mozilla/geckodriver) (for Firefox), [SafariDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/)(for Safari), and [InternetExplorerDriver](https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver) and [MSEdgeDriver](https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/) (IE and Edge respectively). Place these Browser Driver files in a directory that is part of the environment PATH. This will allow a command-line call to the programs to execute them irrespective of the working directory.

### - Install Java Language Bindings

-[Version 3.141.59 (2018)](https://github.com/SeleniumHQ/selenium/releases/download/selenium-3.141.59/selenium-java-3.141.59.zip)

-[Changelog](https://github.com/SeleniumHQ/selenium/blob/trunk/java/CHANGELOG)

-[API Docs  
](https://seleniumhq.github.io/selenium/docs/api/java/index.html)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j53qndj1lv31mkmxvsin.png)

## How to configure Selenium in Eclipse

Here are the steps to configure Selenium Webdriver with Eclipse:

### Step 1: Launch Eclipse

To launch Eclipse double click on the eclipse.exe file in the download location.


### Step 2: Create Workspace in Eclipse

This workspace named “C:\BrowserStack” is like any other folder, which will store all the test scripts. Launch the BrowserStack workspace.

![Creating Workspace in Eclipse](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nhpumxpuutl4i4n1gb3r.png)
_Creating Workspace in Eclipse_


### Step 3: Create New Java Project in the BrowserStack Workspace

Create a new Java Project by clicking on **File > New > Java Project** and name it. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mizfypmlk8zoyl9g1ypj.png)
_Creating a new Java Project_



### Step 4: Create Package and Class under the Java Project 

By clicking on the src folder (which is the source folder), create a new package and name it (BrowserStack). Then right-click on the package name and create a class.  

![Creating Package in the Java Project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4n76nl01i4jd0zob3v1.png)
_Creating Package in the Java Project_


![Creating Class in the BrowserStack Package](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ufgfiflp0uqvbzji9xj4.png)
_Creating Class in the BrowserStack Package_


### Step 5: Add Selenium JARs to the Java Project in Eclipse

To add the Selenium Jars to the BrowserStack Java right click on the BrowserStack Project folder and select the Properties option. In the properties window, click on the **Java Build Path** and **Add External JARs**. Browse and add the downloaded Selenium JARs i.e. Client Combined JAR and all the JARs under the Libs folder, then click **Apply and Close**.

![Adding Selenium JARs in the BrowserStack Project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0673ykj5zqn6q0eqzupw.png)
_Adding Selenium JARs in the BrowserStack Project_


This configures Selenium with Eclipse, making it ready to execute the first test script.


[Automation testing](https://www.browserstack.com/guide/automation-testing-tutorial) using Selenium with Java has simplified software development. Being an open-source tool, it provides an opportunity to speed up the time of execution and remove errors for a better user experience. 

Java is quite popular among the developers, given the extensive support being available, making it a preferred choice as a Selenium Client Language Binding. Selenium with Java has proved helpful in optimizing regression testing and cross browser testing. With the support of Continuous Integration tools like Jenkins, Selenium with Java can be used in continuous delivery models.