Book Image

Learn Selenium

By : UNMESH GUNDECHA, Carl Cocchiaro
Book Image

Learn Selenium

By: UNMESH GUNDECHA, Carl Cocchiaro

Overview of this book

Selenium WebDriver 3.x is an open source API for testing both browser and mobile applications. With the help of this book, you can build a solid foundation and learn to easily perform end-to-end testing on web and mobile browsers. You'll begin by focusing on the Selenium Page Object Model for software development. You'll architect your own framework with a scalable driver class, Java utility classes, and support for third-party tools and plugins. Next, you'll design and build a Selenium Grid from scratch to enable the framework to scale and support different browsers, mobile devices, and platforms. You'll also strategize and handle a rich web UI using the advanced WebDriver API, and learn techniques to tackle real-time challenges in WebDriver. Later chapters will guide you through performing different types of testing, such as cross-browser testing, load testing, and mobile testing. Finally, you will be introduced to data-driven testing, using TestNG to create your own automation framework. By the end of this Learning Path, you'll be able to design your own automation testing framework and perform data-driven testing with Selenium WebDriver. This Learning Path includes content from the following Packt books: • Selenium WebDriver 3 Practical Guide - Second Edition by Unmesh Gundecha • Selenium Framework Design in Data-Driven Testing by Carl Cocchiaro
Table of Contents (25 chapters)
Title Page

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.