Selenium WebDriver GuideWelcome 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?
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.
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.
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
The HTMLUnit Headless Browser allows automated web tests to execute without loading a graphical user interface, which can significantly accelerate testing.
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.
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.
Web tests can use CSS Selectors to locate UI elements
What is the difference between Selenium WebDriver, Selenium IDE
and Selenium RC?
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 is an older version of the Selenium
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 3.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.
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?
- 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
- 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.
isno 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.
Automated testing on multiple Selenium WebDriver endpoints from Ranorex Studio
How to get started with Selenium WebDriver
Selenium WebDriver is built into the Ranorex
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.
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 30-day trial of the full version of Ranorex Studio.