Scientech Easy Selenium WebDriver Tutorial | Architecture & Advantages | Scientech Easy

Tuesday, December 4, 2018

Selenium WebDriver Tutorial | Architecture & Advantages

In this tutorial, we will learn a new interesting topic Selenium WebDriver that is the successor of Selenium RC. In the earlier version of selenium, we needed the Selenium RC server which must be started before executing the test scripts but WebDriver does not require any server to execute the tests on a particular browser. There is a separate web driver for each browser that accepts the selenium commands and drives the browser under the tests. So let's see all the points in detail.

What is Webdriver?

➤ WebDriver is an interface and a pure object-oriented tool.
➤ It is a web automation framework that was designed by Simon Stewart while he was working at ThoughtWorks.
➤ WebDriver is a set of APIs (Application Programming Interface) which provides a lot of capabilities to Selenium tool. It provides a communication facility between languages and browsers.

What is Selenium WebDriver?

Selenium WebDriver is a free and open source library to automate the web applications. It is the merger of two automation framework: Selenium and WebDriver. In 2009, Selenium RC is merged with another testing framework called WebDriver to create a new Selenium tool known as Selenium 2.0 or Selenium WebDriver. It was released in July 2011. It is the first choice of any tester to automate the web applications.

Selenium WebDriver Architecture

Selenium WebDriver Architecture consists of four basic components. There are as follows:
1. Selenium Language Bindings.
2. JSON Wire Protocol
3. Browser Drivers
4. Real Browsers.
The following picture shows the architectural representation of Selenium WebDriver.
Selenium WebDriver Architecture, Selenium WebDriver example

Details of each component: 
1. Selenium Language Binding/Selenium Client Libraries
Selenium tests can be written in multiple programming languages such as Java, Ruby, Python etc. Therefore, Selenium Developers have decided to develop a language bindings or Selenium Client Libraries that allow selenium to support multiple languages such as Java, Ruby, Python etc. It is nothing but different Jar files. These client libraries have Selenium WebDriver classes and methods that are needed to create automation test scripts and can be installed using package installers available with the respective languages. For instance, Suppose you want to use browser driver in Java, you will use the Java client libraries or Java jar files. All the supported Selenium client libraries can be downloaded from the official website ( of selenium.

Note: Selenium Client Libraries is not testing framework. A Selenium client library provides an application programming interface(API), i.e, a set of functions that executes the selenium commands from the program.

JSON stands for JavaScript Object Notation. It is a very popular data interchange format based on the subset of JavaScript Programming Language which was developed by Douglas Crockford.  It is used to exchange the data between the client and server on the web. It supports data format available in all popular languages like Java, C#, Python, Ruby etc. 
JSON Wire Protocol is a transport mechanism created by WebDriver developers which transfers the data between a server and a client on the web. It uses a REST API  to transfer the information between HTTP server. Each browser driver such as FirefoxDriver, ChromeDriver, IEDriver etc has its own HTTP server.

3. Browser Drivers
Selenium uses a specific driver for each browser to establish a secure communication with the respective browser without revealing the internal logic of browser's functionality. This browser driver receives the requests from the language binding and invokes the relevant operations on the browser. Each type of browser has its own driver that implements WebDriver's wire protocol for that specific browser. 

4. Real and Headless Browser
Selenium Web driver supports both real and headless browser. For example, If you want to automate tests with selenium web driver and execute the script in the real browser like Chrome, you have to download its specific driver application. This must be done for all browsers that you want to use. GeckoDriver(Firefox), ChromeDriver, and IE Driver are the example of the most frequently used driver and follow the guidelines of the Selenium framework. 
The example of the headless browser is HTMLUnit browser(HTMLUnitDriver). 

Let's see how Selenium WebDriver works internally? 
➲ In real time scenario, When you write a code in your Eclipse IDE using any one of the supported Selenium client libraries (say Java), you will click Run option to execute the program source code. After clicking the Run, Firefox browser will be launched and it will navigate to the URL of the website. Now let's understand what is happening internally after clicking the Run till the launch of Firefox browser.

When you execute any test script using the web driver, the following steps are performed internally.
1. As you click on Run, The Selenium client library run Selenium commands from your own program and convert them into the JSON format(shown below) and sends to the browser driver (say FirefoxDriver) for each command
    https://localhost:7705/ {"url": ""}
 in a serialized JSON format using JSON Wire Protocol over the HTTP.  Each browser driver uses the HTTP server to receive an HTTP request. 

2. JSON Wire Protocol communicates between the client and the server by transferring the data. The browser driver receives the HTTP request through HTTP Server. The HTTP Server performs all the specific actions or instructions on the real browser and then the browser will send a request to load URL. 

3. After performing all instructions, Execution status is sent back to HTTP Server over the HTTP. The browser driver again uses the HTTP server to receive the HTTP request and send back to the client library via JSON Wire Protocol. The client library passes it back to your program. The program will report as a success or failure.  

Features of Selenium WebDriver

There are so many important features of Selenium WebDriver. They are as follows:
Features of Selenium WebDriver, Properties of Selenium WebDriver.

1. Multiple Browser Support: Selenium WebDriver supports a diverse range of multiple web browser and their version such as Firefox, Chrome, Internet Explorer, Safari, Opera etc. It also supports Headless browser called HTMLUnit browser. HTMLUnit browser is a non-conventional browser.

2. Multiple Languages Support: WebDriver also supports most of the commonly used programming languages such as Java, C#, Python, Ruby, Pearl, PHP, JavaScript. You don't have to know all of them. WebDriver provides facility to choose any one of the programming languages based on competency and starts to create test scripts. 

3. Speed: WebDriver performs the faster operation as compared to other tools of Selenium Suite. Unlike Selenium RC, It does not require any intermediate server for communicating with the browser. It provides direct communication between the WebDriver Client Libraries and Web Browser.

4. Simple and Easy Commands: Selenium WebDriver provides very simple and easy commands to implement in the scripts. For example, If you want to launch the browser using web driver, the following commands have to use:
WebDriver driver=new FirefoxDriver(); (Firefox browser)
WebDriver driver=new ChromeDriver(); (Chrome Browser)
WebDriver driver=new InternetExplorerDriver(); (Internet Explorer Browser)

5. Drivers, Methods, and Classes: Selenium web driver offers multiple solutions to handle some potential challenges in the automation testing. It also helps the testers in the easy way to handle with the complex type of web elements such as checkboxes, dropdowns, and alerts with the help of dynamic finders. 

6. Record & Playback: Web driver does not support record and playback features like Selenium IDE.
7. Dynamic Finder: It also supports dynamic finder for locating the web element on the web pages. 

Advantages of Selenium WebDriver

Some of the most important advantages of Selenium WebDriver are as follows:
 Selenium WebDriver is an open source, freeware, and portable tool.
 It supports different operating system like Windows, Mac or Linux etc.
 It also supports third-party tools such as AutoIt, Apache POI. 
 It supports parallel test execution that reduces the time taken in executing the parallel test cases.
 Selenium web driver also supports iPhone and Android operating system. 
 It supports the implementation of Dynamic finder and Listener.
 Starting up a server in web driver is not required before the execution of test scripts.
 It can be integrated with third-party tools like TestNG and JUnit for grouping the test cases and generating test reports.
 By using selenium web driver, we can achieve Continuous Testing by integrating with Maven, Jenkins, and Docker. 

Limitations/Drawbacks of Selenium WebDriver

There are some limitations that occur in selenium web driver. They are as follows:
 Selenium WebDriver can be used only to test web-based applications. We can not test Windows-based applications or desktop applications and any other software. You will have to use a third-party tool like AutoIt for testing of Windows-based applications.
 It is not possible to perform the testing on the image. We can perform image-based testing by integrating selenium with Sikuli.
 WebDriver does not generate automatically test result file. We need to integrate with third-party frameworks like TestNG or JUnit for generating test reports.
 WebDriver cannot support new browsers. 
 Selenium doesn't support built-in add-ins assistance.

Selenium WebDriver Vs Selenium RC

There was a lot of limitations in Selenium RC which eventually led to the development of Selenium WebDriver. 
Let's see how Selenium WebDriver differs from the Selenium RC.
SN Selenium WebDriver Selenium RC
1. The architecture of Selenium WebDriver is simpler as compared to the Selenium RC because it controls the browser directly from the OS(Operating System) level. Selenium RC's architecture is more complicated because it uses an intermediate Selenium Remote Control Server to communicate with the browser.
2. Selenium WebDriver performs faster as compared to the Selenium RC because it interacts directly with the browser without using any external proxy server. Selnium RC is slower because it uses a JavaScript program called Selenium Core whose commands give the instructions to the browser.
3. Selenium WebDriver is pure object oriented API. Selenium RC is semi object oriented API.
4. It supports both real and headless browser like HTMLUnit browser. Selenium RC does not support headless browser. It supports only real browser.
5. WebDriver supports OS(Operating System) for mobile applications such as iOS, Windows mobile, and Android. Selenium RC does not support testing of mobile apllications.
6. WebDriver supports Dynamic finder and Listener. Selenium RC does not support.

Final words
We hope that this tutorial has covered all the important points related to the Selenium WebDriver, Selenium WebDriver Architecture, Features of Selenium WebDriver, and advantages. We have tried to understand you all topics in a simple process and an easy way.