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...
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.
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
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 /
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
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
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
The Microsoft Edge WebDriver is provided by Microsoft for automated web testing.
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.
Web tests can use CSS Selectors to locate UI elements
What is the difference between Selenium WebDriver, Selenium IDE and Selenium RC?
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
Selenium RC is an older version of the Selenium
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
What is a Selenium Grid?
A Selenium grid is a network of devices that
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?
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
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
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
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.
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
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...
Benefits of Using the Top BDD Testing Tools
Explore the most popular and best types of BDD testing tools available for developers across different programming languages and development platforms.
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...