How to Install Selenium Webdriver for Java
October 25, 2021

How to Install Selenium WebDriver for Java

Open Source Automation

Testing modern complex applications can turn into a tedious task for a tester. To minimize these difficulties, an automation testing framework using Selenium WebDriver can help. By using this Selenium framework, testers can easily write their test cases efficiently and in less time. They don’t even have to know Selenium WebDriver in detail to do so.

In this article, you will learn about installing Selenium WebDriver for Java installation, as well as what Selenium WebDriver is and why we should use it.

Back to top

Why Install Selenium WebDriver?

Selenium is an open-source tool used to perform automated testing on web browsers like Firefox, Chrome, Edge, Safari, etc. Selenium can only test web applications, so you cannot use Selenium to test any desktop applications.

WebDriver is the most important Selenium component. It is a web framework that allows the tester to execute cross-browser testing. To create the test scripts, there is an option to choose a programming language, such as Java, JavaScript, Python, and C#/Ruby. 

Selenium WebDriver is designed in accordance with the client/server model. It communicates with the browser through the driver and data is communicated through the HTTP protocol. As long as the data format and protocol can be parsed by the server, WebDriver supports cross-platform, multi-language, and multi-browser.

This WebDriver framework Architecture has four major components:

1. Selenium Client library

2. JSON wire protocol over HTTP

3. Browser Drivers

4. Real Browsers

The functionality and usability of your software applications will determine your business growth. The same can be said for your web applications, because many businesses today rely on the Internet. Take any e-commerce company as an example. Whether it's Amazon or eBay or Flipkart, they all rely on customer traffic to their websites and business traffic on web-based mobile applications.

Selenium WebDriver comes in before deployment, as an automated software testing tool that ensures your software is functioning and performing properly, to help your business grow.

Back to top

Selenium WebDriver Capabilities

Selenium WebDriver is popular due to its capability to handle the testing work per the testing requirements. Some of the major features and benefits are listed below:

1. Multi-Browser Support

Selenium WebDriver supports various Internet browsers, such as Chrome, Firefox, Opera, etc. Likewise, it also supports parts of unconventional programs such as HTMLUnit. HTMLUnit is a headless browser that does not use a GUI (graphical user interface).

2. Various Language Support

WebDriver also supports a large number of languages commonly used in programming, such as Java, C#, JavaScript, PHP, Ruby, Pearl, and Python. Subsequently, the client can select any supported programming language according to its capabilities and start building test content.

3. Speed

The performance of WebDriver is faster when compared with different devices in the Selenium suite. It does not require any intermediate road workers to talk to the program; instead, the device directly talks to the program.

4. Open-Source

Selenium is an open-source and portable web testing framework. This makes it free, and it also has a vibrant support community.

5. Parallel Test Execution

It also supports parallel test execution, thereby reducing time and improving test efficiency.

6. No Server Installation

The Selenium Web driver does not require server installation, and the test script can directly interact with the browser.

7. Easy Report Generation

WebDriver can be integrated with testing frameworks such as TestNG for application testing and report generation.

8. Remote (and Local) Execution 

In addition to local execution, Selenium WebDriver enables remote test execution. This is the use of remote machines to run tests simultaneously and across a variety of test environments, such as operating systems, browsers, and system configurations. The ability to run test automation on numerous remote machines as well as multiple browsers is enabled with Remote WebDriver. This is especially helpful in a distributed setting where hundreds or even thousands of tests must be run on a regular basis.  

Back to top

How to Install Selenium WebDriver 

The process of installing Selenium WebDriver is made of many parts. We will go through:

  1. Installing Java on your computer system.
  2. Installing and configuring Eclipse. Eclipse is required to generate test cases.
  3. Installing the Selenium Java Client.
  4. Selenium WebDriver configuration.
  5. Installing Maven. Maven will take care of the build compilation, documentation, the creation of a correct project structure and the management of jar files in the project's build path.
  6. Creating a package.

Step 1 - Installing Java 

Installing Java is comprised of three steps: -

  1. JDK Install
  2. Configure Variable Environment
  3. JRE install

It might be confusing to understand why we need to both install JDK and JRE. So, let me explain the differences between them. JDK is used for developing testing and debugging apps and java applets. On the other hand, JRE provides libraries like JVM and other with the required components to run the applications which are written in java. 

Choose the correct one per your system requirement (as shown below in the image) and download the file. Just wait for a while as it downloads.

installing java

Now, follow the instructions given below.

Java installation instructions

By clicking on NEXT you will see a message stating that the JDK was successfully installed.

JDK successful installation message

In the image below you can see that both the JDK and JRE packages were installed together. This is a complete Java development kit.

Complete JDK

Setup - Environment Variable 

Search for “Advanced system setting” and open “System properties”. Click on Environment Variables. Under the system variables, you have to set the path for java. 

setting the path for Java under Environment Variables
Adding new variables

Click on the New button and write the new name of java variables. The variable name ( Java_Home_New), and the variable value will be the java path (you can see my path in the image below).

Writing new variable name

After entering the variable name and variable value (path) and clicking on the OK button, you should get a screen like the figure below.

Java_Home_New added to system variables

To verify the version of java installed, open the command prompt and hit the command>>  Java -version 

Opened command prompt

Step 2 - Installing Eclipse IDE

To install Eclipse IDE, you first have to download the latest version of the Eclipse for Java EE (enterprise Edition) developer, because it is a complete package that will be useful for the Java standard edition. Download the link marked by the arrow sign in the figure below. (Make sure to make the correct choice between the 32-bit and 64-bit versions of Windows).

installing Eclipse IDE

After the installation process is completed, double click on the eclispse.exe file to launch Eclipse.

 

Launch Eclipse

Then you have to extract the zip file and run the application as administrator.

Step 3 - Download Selenium Java Client Driver

We’re now ready to move on to installing Selenium!

After you click the web page to download the Selenium WebDriver for the Java client, scroll down through the web page and locate the Selenium client and WebDriver Language Bindings. Click on the “Download” link of the Java client driver as shown in the figure below.

Downloading Java client driver

The downloaded zip file named “selenium-3.14 zip” will be in a zip format. Unpack the contents in a convenient directory. It contains the essential jar files required to configure Selenium WebDriver in Eclipse IDE.

unlocking zip file

Step 4 - Selenium WebDriver Configuration

Once Java and Eclipse are both installed the final steps are to configure Eclipse IDE with Selenium WebDriver.  

Configuring Eclipse IDE with Selenium Web Driver

Let's see how to create a new Java Project in Eclipse.

1. Launch Eclipse IDE: Launch the “eclipse.exe” file in the eclipse folder. In my case, the executable file is located at E:\eclipse\eclipse.exe.

2. When the system asks to select a workplace, choose the default location.

selecting workspace

3. After clicking on OK, the Java Eclipse window will launch. Now, you can start creating a new project.

4. To create a new project, go to file > New > Java Project. 

creating a java project

5. Clicking on Java Project will open a new pop-up window. Enter the details as follows:

  • Step 1 - Create the Project Name
  • Step 2 - Enter the Path of the project
  • Step 3 - Select the execute environment JRE
  • Step 4 - Select project layout
  • Step 5 - Click on Finish

6. After clicking on the Finish Button, the New Java Project starts showing with the latest version.

Step 5 - Integrating Eclipse with Maven

Installing the Maven plugin for Eclipse will help manage your project. In many cases, the Maven plug-in is automatically installed in Eclipse. If it’s missing, go to Eclipse MarketPlace, search for Maven, and then download the M2E integrated version.

Integrating Eclipse with Maven

 Click on Install Now and then on the Confirm button:

Confirming Maven installation

After that, the software will start installing and then Eclipse will restart.

To create a Maven project, perform the following steps:

1. Go to File -> New a Project

Creating new Maven project

2. Expand the Maven folder and select the Maven Project option, then click NEXT.

Selecting Maven project option

3. Click the Next button once again to proceed.

4. Select a Maven template type, give a group ID, and an Artifact ID. Automatically get a Java project with a correct project structure and a POM.xml when creating a project.

5. If you already have an existing Java project, and after learning about Maven you want to change it to a Maven project, then just right-click on the project in the project explorer and select Configure -> Convert to Maven project.

Step 6 - Package Creation 

Now we have to create a package under the new Java project (named “Selenium” in my case). 

installing selenium webdriver by creating a package in Java

1. Right-click on the src file under selenium > New > Package, a pop-up window will open up.

2. Enter the name of the package (here in my case name is “ doctech ” Note- use lower case).

3. Click on the “Finish” Button

Finish button

Now we will create a new Java class under the new package (named “doctech”) by right-clicking on it and the go-to select New > class. The steps below will help you to create a new Class.

 

Creating a new class

 

 4. After clicking on Class, a pop-up window will open. Enter the following details:

  • Create the name of the class
  • Click on the “Finish” button
Finish button

 When the Class has been created, the windows look like the image below.

Class creation screenshot

Now, we will “Build path” by right-clicking on “JRE system Library Java”. Follow the steps shown in the image:

build path

Then, follow these steps to add dependencies for Selenium:

  1. Right click on JRE system library
  2. Under the properties dialog click on Java Build Path
  3. Click on the Libraries tab
  4. Click on Add external JAR to add external JARs.
Adding Selenium dependencies

When you click on “Add External JAR”, a pop-up window will open and you have to browse the jar file from your given location and click on OPEN. 

Select two jar files like the below image shows:

Selecting two jar files

You will now see the jar files under the libraries tab:

Jar files under libraries tab

Add all JAR files outside and inside the libs folder:

JAR files

Click the OK button and finally, you have completed importing the Selenium library into your project!

Yes, finally everything is set and you can start using Selenium.  

Back to top

Bottom Line

In this article, you learned about Selenium WebDrivers and how to install Selenium with Java. I hope you understood the concepts and that they added valuable knowledge to you.

See how you can leverage Selenium through BlazeMeter. Start testing with BlazeMeter today.

START TESTING NOW

 

Related Resources

Back to top