Book Image

Selenium WebDriver 3 Practical Guide - Second Edition

By : Pallavi Sharma, UNMESH GUNDECHA, Satya Avasarala
Book Image

Selenium WebDriver 3 Practical Guide - Second Edition

By: Pallavi Sharma, UNMESH GUNDECHA, Satya Avasarala

Overview of this book

Selenium WebDriver is an open source automation tool implemented through a browser-specific driver, which sends commands to a browser and retrieves results. The latest version of Selenium 3 brings with it a lot of new features that change the way you use and setup Selenium WebDriver. This book covers all those features along with the source code, including a demo website that allows you to work with an HMTL5 application and other examples throughout the book. Selenium WebDriver 3 Practical Guide will walk you through the various APIs of Selenium WebDriver, which are used in automation tests, followed by a discussion of the various WebDriver implementations available. You will learn to strategize and handle rich web UI using advanced WebDriver API along with real-time challenges faced in WebDriver and solutions to handle them. You will discover different types and domains of testing such as cross-browser testing, load testing, and mobile testing with Selenium. Finally, you will also be introduced to data-driven testing using TestNG to create your own automation framework. By the end of this book, you will be able to select any web application and automate it the way you want.
Table of Contents (14 chapters)

Selenium Testing Tools

Selenium 3.0 offers three important tools, Selenium WebDriver, Selenium Server, and Selenium IDE. Each of these tools provides features to create, debug, and run tests on supported browsers and operating systems. Let's explore each of them in detail.

Selenium WebDriver

Selenium WebDriver is the successor of Selenium RC (Remote Control), which has been officially deprecated. Selenium WebDriver accepts commands using the JSON-Wire protocol (also called Client API) and sends them to a browser launched by the specific driver class (such as ChromeDriver, FirefoxDriver, or IEDriver). This is implemented through a browser-specific browser driver. It works with the following sequence:

  1. The driver listens to the commands from Selenium
  2. It converts these commands into the browser's native API
  3. The driver takes the result of native commands and sends the result back to Selenium:

We can use Selenium WebDriver to do the following:

  • Create robust, browser-based regression automation
  • Scale and distribute scripts across many browsers and platforms
  • Create scripts in your favourite programming language

Selenium WebDriver offers a collection of language-specific bindings (client libraries) to drive a browser. WebDriver comes with a better set of APIs that meet the expectations of most developers by being similar to object-oriented programming in its implementation. WebDriver is being actively developed over a period of time, and you can see many advanced interactions with the web as well as mobile applications.

The Selenium Client API is a language-specific Selenium library that provides a consistent Selenium API in programming languages such as Java, C#, Python, Ruby, and JavaScript. These languages bindings let tests to launch a WebDriver session and communicate with the browser or Selenium Server.

Selenium Server

Selenium Server allows us to run tests on browser instances running on remote machines and in parallel, thus spreading a load of testing across several machines. We can create a Selenium Grid, where one server runs as the Hub, managing a pool of Nodes. We can configure our tests to connect to the Hub, which then obtains a node that is free and matches the browser we need to run the tests. The hub has a list of nodes that provide access to browser instances, and lets tests use these instances similarly to a load balancer. Selenium Grid enables us to execute tests in parallel on multiple machines by managing different types of browsers, their versions, and operating system configurations centrally.

Selenium IDE

Selenium IDE is a Firefox add-on that allows users to record, edit, debug, and play back tests captured in the Selenese format, which was introduced in the Selenium Core version. It also provides us with the ability to convert these tests into the Selenium RC or Selenium WebDriver format. We can use Selenium IDE to do the following:

  • Create quick and simple scripts using record and replay, or use them in exploratory testing
  • Create scripts to aid in automation-aided exploratory testing
  • Create macros to perform repetitive tasks on Web pages
The Selenium IDE for Firefox stopped working after the Firefox 55 moved to the WebExtension format from XPI format and it is currently no longer maintained.