Selenium Testing Guide

Dec 14, 2023 | Product Insights, Test Automation Insights

Selenium WebDriver Guide

Welcome to this introduction to Selenium WebDriver. After reading this guide, you will understand what Selenium Webdriver is, how it works, and how to use WebDriver to automate web testing. You will also understand how Ranorex integrates with Selenium WebDriver to provide the full functionality of Ranorex Studio in combination with the power of Selenium WebDriver and Selenium Grids. Before reading this guide, it will be helpful to have a basic understanding of web application testing.

What is Selenium WebDriver?

Selenium WebDriver is a free, open-source framework that provides a common application programming interface (API) for browser automation. Ideally, modern web browsers should all render a web application in the same way. However, each browser has its own rendering engine and handles HTML a little differently, which is why testing is needed to ensure that an application performs consistently across browsers and devices. The same browser compatibility issues that affect web applications could also affect automated web tests. But automated tests that use the Selenium client API can run against any browser with a WebDriver-compliant driver, including Chrome, Safari, Internet Explorer, Microsoft Edge, and Firefox.

Selenium WebDriver can run on Windows, Linux and macOS platforms. Tests can be written for Selenium WebDriver in any of the programming languages supported by the Selenium project, including Java, C#, Ruby, Python, and JavaScript. These programming languages communicate with Selenium WebDriver by calling methods in the Selenium client API.

Webdriver workflow

The Selenium WebDriver workflow

Looking deeper: For a programming language to work with Selenium, it must include a library that understands either the current Selenium JSON Wire Protocol or the emerging W3C WebDriver protocol. Information about the W3C WebDriver protocol candidate recommendation can be found on GitHub.

What browsers can be tested with Selenium WebDriver?

Selenium WebDriver can automate tests for all popular browsers. Each browser requires its own specific driver to communicate with Selenium tests, as described below. Additional information and download links for the individual browser drivers are available on the SeleniumHQ download page.

Apple Safari icon

Apple Safari

Safari 10 provides native support for the WebDriver API, so there is no need to download a driver from the SeleniumHQ website. The Safari Driver can be launched directly from the /usr/bin/safaridriver executable. Most Selenium language-specific client libraries will launch the Safari driver without additional configuration.

Google Chrome icon

Google Chrome

Unlike Safari, running automated tests on the Google Chrome browser requires a separate executable, the ChromeDriver. This executable is maintained by the Chromium team with assistance from Selenium WebDriver contributors, and is available for download from Google.

HTMLUnit Headless Browser icon

HTMLUnit Headless Browser

The HTMLUnit Headless Browser allows automated web tests to execute without loading a graphical user interface, which can significantly accelerate testing.

Internet Explorer icon

Internet Explorer

Although Microsoft introduced the Edge browser some time ago, many Windows users are still using Internet Explorer, or have switched to another browser, such as Chrome. The Selenium project provides the InternetExplorerDriver.

Microsoft Edge icon

Microsoft Edge

The Microsoft Edge WebDriver is provided by Microsoft for automated web testing.

Mozilla Firefox icon

Mozilla Firefox

Testing Firefox browser versions 47.0.1 and above requires the Mozilla GeckoDriver. “Gecko” is the name of the web browser rendering engine used in FireFox as well as other Mozilla applications, such as the Thunderbird email client.

How does Selenium WebDriver work?

Selenium WebDriver consists of a language-specific client, a remote server, and browser-specific drivers. The Selenium WebDriver client API submits a request to the remote server, which forwards it to a browser-specific driver, such as the Chrome Driver or the Safari Driver. The browser driver launches the browser to perform the action, and then returns a response to the client. A list of WebDriver commands can be found on the Mozilla developer site.

To perform an action such as entering data in a field or clicking a button, a client request must find the particular GUI element that is the target of the action. Selenium can use several ways to locate an element, including attributes such as the element ID, name, XPath, link text, or CSS selector.  The best locator to use is one that is stable and unique to the web element. While the element’s ID often meets these requirements, be aware that some web elements have dynamic IDs that change each time the page loads. Elements with dynamic IDs require a different locator strategy, such as CSS selector or XPath.

Generating unique and stable locators can be difficult and time-consuming. Ranorex provides a free extension for the Chrome DevTools, Selocity, that automates that process of generating locators. With this browser extension, you can explore the document object model (DOM) of a web page and generate selectors in the DevTools sidebar panel. Selocity applies best practices such as depending on the HTML structure of the page as little as possible, such as preferring data-oriented elements and attributes over layout-oriented ones, and ignoring dynamic IDs.

Selocity painpoint selector

Web tests can use CSS Selectors to locate UI elements

What is the difference between Selenium WebDriver, Selenium IDE and Selenium RC?

Icon selenium IDE

Selenium IDE

Selenium IDE is an integrated development environment for automating web tests that includes a record-and-replay tool. It was developed as an add-on for the Firefox browser. Scripts are recorded in the Selenium-specific scripting language Selenese, which has commands for actions such as clicking a link and fetching data from web pages. Because of changes in the FireFox browser, the Selenium IDE no longer works as of Firefox release 55.

Selenium RC logo

Selenium RC

Selenium RC is an older version of the Selenium project, and is also referred to as Selenium 1.0. The RC in its name stands for “Remote Control.” Selenium RC consists of a set language-specific client libraries plus a standalone server. The Selenium RC server handles the work of starting and stopping a browser, passing commands from a test program to the browser, and sending back the results. To execute the test commands, the RC server injects Javascript into the target browser.

Selenium logo

Selenium WebDriver

The Selenium RC project was merged with the separate WebDriver project to create Selenium WebDriver, also known as Selenium 2.0. The latest version, Selenium 4.0, was released in October 2016. This release replaced the original Selenium Core with one based on the WebDriver, so that it was no longer necessary to install and configure a Selenium Server separately from the WebDriver listener.

What is a Selenium Grid?

A Selenium grid is a network of devices that allows scalable, distributed web testing. It consists of a hub and one or more nodes on local or remote devices, which may be physical or virtual. Using a grid architecture to execute automated tests in parallel can greatly accelerate testing, and also gets around the limitation that a single node can have only one version of a particular browser installed.

The hub controls the distributed testing process. Each node registers with the hub to identify the specific versions of browsers available on the hub. An automated test must pass a JSON object containing the desired capabilities for the test, such as the OS and browser version, to the remote browser-specific driver. This allows the hub to route the test to a matching node. If there are no matching nodes for the specified capabilities, the test will not run.

selenium grid

Distributed testing with a Selenium Grid

There are several approaches to building a Selenium Grid:

  • Build a custom Selenium Grid in-house using one or more physical or virtual servers, each configured with the required operating systems and browsers
  • Implement a cloud-hosted solution grid solution such as the ones available from SauceLabs or Browserstack
  • Implement a proprietary in-house solution such as Selenium Box from Element34 Solutions

Why use Selenium WebDriver for web testing?

Smiley positive

Benefits

  • Selenium Webdriver is free and open-source
  • The Selenium project is promoted by leaders in the web development and software testing industries
  • It will support the emerging W3C WebDriver standard
  • It offers the ability to run tests in parallel using Selenium Grids
Smiley neutral

Challenges

  • Selenium Webdriver is complex to install and configure
  • Building automated tests requires advanced programming knowledge, especially since there is no capture-and-replay functionality
  • The Selenium IDE no longer works in Firefox version 55 and later, due to changes in the Firefox browser.
  • There is no built-in test results reporting functionality

Why use Ranorex Studio with Selenium WebDriver?

Selenium WebDriver is part of the Ranorex core API, so that you can automate web application tests without programming using the Ranorex Recorder, or using standard languages C# and VB.NET in Ranorex Studio’s full IDE. Ranorex supports executing remote tests in Selenium WebDriver and on Selenium grids. To do this, all that is necessary is to set up a WebDriver server as an endpoint for Ranorex tests, and configure the endpoint’s capabilities in JSON format using the Ranorex Capabilities Configurator. You can configure local or remote endpoints, or even a cloud-hosted one such as SauceLabs.

There are many benefits to using Selenium WebDriver from within Ranorex Studio. Ranorex uses the standard WebDriver Wire Protocol to communicate with browser instances via their specific drivers. While the Selenium API sends JSON data over the WebDriver to execute actions on an endpoint, Ranorex uses proprietary automation technology and the RanoreXPath for fast and reliable performance. Ranorex Spy makes it easier to uniquely identify web application elements, which can be stored in the Ranorex Repository and shared with other testers. Ranorex Studio also includes built-in reporting.

webtesting endpoints

Automated testing on multiple Selenium WebDriver endpoints from Ranorex Studio

How to get started with Selenium WebDriver

Selenium WebDriver is built into the Ranorex core, so that you can leverage all of the power of Selenium WebDriver – along with Ranorex Studio’s tools for element identification, timeout handling, capture-and-replay codeless automation, full IDE, and built-in reporting. Ranorex Studio supports running tests in parallel using either a Selenium Grid or Ranorex’s own Parallel Runner.

If you prefer to set up your own Selenium tests by hand, first select a programming language and IDE to use with Selenium Webdriver – such as C# or JavaScript with Microsoft Visual Studio, or Java with Eclipse. Then, download and install the Selenium Server and the Selenium Webdriver client API for your chosen programming language. Next, download and install your target browser, such as Chrome, on your test device. You will also need the browser-specific driver, such as the ChromeDriver. For a step-by-step tutorial on setting up WebDriver for Java with Eclipse, refer to the Selenium Setup Guide at AutomationTestingHub.

tipp icon

Tip

To learn more about Ranorex Studio’s deep integration with Selenium WebDriver, watch one of our webinars live or on-demand, or download a free trial of the full version of Ranorex Studio.

Related Posts:

Effective Black Box Testing Methods You Need to Try

Effective Black Box Testing Methods You Need to Try

When users open software solutions, they expect them to function as needed. For example, when a business analyst opens Excel, they hope to work with data without requiring knowledge of what’s happening with the application internally. If something breaks, they won’t...

8 Steps to Create a Data Migration Plan

8 Steps to Create a Data Migration Plan

When companies change systems or move information to a more secure location, they typically need to perform a data migration. If a company wants to use cloud-based solutions, it must transfer existing information from localized hardware to a cloud environment. A...