Introduction to Selenium WebDriver – Selenium Tutorial #8

Introduction to Selenium WebDriver:

Earlier in this series, we published tutorials which focused more on Selenium IDE and its various aspects. We introduced the tool and discussed about its features. We also constructed a few scripts using Selenium IDE and Firebug. From there we moved on to different types of web elements available and their locating strategies.

Now that we are well versed with Selenium IDE, let us move our learning curve towards creating more advanced automation scripts using Selenium WebDriver. WebDriver is one of the most compelling automation testing tools. Let us discuss it in detail.

What You Will Learn:

Introduction

WebDriver is one of the most powerful and popular tools of Selenium toolkit. WebDriver comes as an extended version of Selenium RC with superfluous advantages and addresses many of its limitations. WebDriver extends its support to many latest browsers and platforms, unlike Selenium IDE. WebDriver also doesn’t require Selenium server to be started prior to execution of the test scripts, unlike Selenium RC.

Selenium RC in aggregation with WebDriver API is known as Selenium 2.0. Selenium was so developed in order to support dynamic web pages and Ajax calls. It also supports various drivers to exercise web-based mobile testing.

Architecture

WebDriver is a web-based testing tool with a subtle difference with Selenium RC. Since the tool was built on the fundamental where an isolated client was created for each of the web browsers; no JavaScript Heavy lifting was required as we discussed in our very first tutorial.

WebDriver makes direct calls to the Web browser and the entire test script is executed in this fashion. WebDriver uses the browsers support and capabilities to automation.

Unlike Selenium RC, Selenium WebDriver doesn’t essentially require Selenium Server to be started before launching the test script execution. The user can leverage the benefit and may or may not require Selenium Server if he/she desires to perform the test execution on the same machine where the browser is residing.

Exceptional Cases when Selenium Server is required with WebDriver:

WebDriver is a purely object-oriented framework that works on OS layer. It utilizes the browser’s native compatibility to automation without using any peripheral entity. With the increasing demand, it has gained a large popularity, user base and has become by far one of the most extensively used open source automation testing tools.

Features of Selenium WebDriver

Browser Compatibility

WebDriver supports a diverse range of web browsers and their versions. It supports all the conventional browsers in addition to some unique and rare browsers like HtmlUnit browser unlike Selenium RC and Selenium IDE.

HtmlUnit Browser executes the test scripts analogous to other browsers except the fact that it runs in the headless mode i.e. GUI-less mode and the user won’t be able to view the test script execution. Said that the test script execution transpires in headless mode, thus the execution speed takes a roll and quickens the execution.

WebDriver also supports web-based mobile testing. Thus it provides AndroidDriver and IphoneDriver to back web-based mobile testing.

Note: WebDriver doesn’t readily support new browsers.

Language Support

Earlier in the sessions, we learned to create scripts using record and playback functionality. We also saw how to create them manually using Selenese commands. While creating such test scripts, we come across various constraints.

Some of the limitations imposed by Selenium IDE are:



The above impediments can be troubleshot programmatically. WebDriver facilitates the user to choose within the different programming languages and build their test script in the designated language.

Selenium WebDriver supported programming languages are:

  1. Java
  2. C#
  3. PHP
  4. Pearl
  5. Ruby
  6. Python

Thus the user can pick any one of the programming language (provided the language is supported by WebDriver) based on his/her competency and can start building test scripts.

Speed

When compared to other tools of Selenium suite, WebDriver turns out to be the fastest tool amongst all. The communication is not channelized via any external intervention; rather the tool directly communicates with the browser same as that of any user. Thus, WebDriver takes advantage of the browser’s native compatibility towards automation.

Other tools from Selenium suite like Selenium RC don’t communicate directly with the web browser. Client libraries (test scripts are written in any programming language) communicate with Selenium Remote Control Server and Remote Control communicates with a Selenium Core (JavaScript Program) which in turn communicates with the web browser. Hence, this sort of twisted communication results as a hindrance on execution speed.

Drivers, Methods and Classes

WebDriver offers a wide range of solutions to some potential challenges in Automation Testing. It helps us to deal with complex types of web elements like checkboxes, dropdowns, and alerts with the help of dynamic finders.

With the advent of the mobile era, WebDriver API has also matured and introduced some of the key technologies to enter this horizon. WebDriver enables the user to perform web-based mobile testing. It provides two of the essentials drivers to perform web-based mobile testing.

Moreover, WebDriver API is fairly simple and easy. It doesn’t include repetitious commands. On the contrary, Selenium RC embodies many of the tautological commands.

Conclusion

In this tutorial, we tried to make you acquainted with Selenium WebDriver by outlining its architecture, features and limitations.

Here are the cruxes of this article.

Next Tutorial #9: In the next tutorial, we would be discussing about the installation procedure to get started with WebDriver initiating from the scratch. We would also be discussing about the diverse range of drivers provided by WebDriver, each catering to different needs.

Till the time our next tutorial is under construction, the readers can visit the Selenium’s official website. A detailed documentation with reference to Selenium WebDriver is implemented at its official website.

About the author: Shruti Shrivastava is currently working as a Senior Test Engineer with 4+ years of automation testing experience. She is an ISTQB certified professional and also an active blogger, always interested in solving testing related problems.

We also have two more authors on this Selenium tutorial’s series to make it complete, useful and relevant.

If you have any specific requests/queries about this or any other tutorial in this Selenium online training series, let us know in comments.