Understanding Selenium WebDriver Architecture with Examples
Arjit Yadav
QA Automation Engineer | ISTQB | Azure DevOps | API Testing | JMeter | Appium | Selenium | Playwright | Helping drive software quality through smart automation
In the previous edition we delved into the different parts of Selenium, its benefits, and its drawbacks. Now, we're diving deeper into the core of the Selenium WebDriver.
Selenium WebDriver Architecture
Understanding the architecture of Selenium WebDriver is crucial for mastering web UI automation. To get a grip on this structure, let's break down the four main components that make up this framework.
1. Selenium Client Library
The Selenium WebDriver developers have made it adaptable to various programming languages. This component, known as the Selenium Client Library or language bindings, enables us to write automation scripts in languages like Java, Python, C#, Ruby, and JavaScript.
2. Browser Drivers
Each supported browser in Selenium has its dedicated browser driver. These drivers take commands from Selenium scripts and convey them to the respective browsers. Importantly, this communication occurs without exposing the internal workings of the browsers. Examples of browser drivers include EdgeDriver, ChromeDriver, FirefoxDriver, etc.
In the architecture of Selenium WebDriver, the W3C (World Wide Web Consortium) serves a vital role in standardizing the WebDriver protocol. This protocol acts as a common language that facilitates communication between web browsers and automation tools. The W3C's involvement ensures that this protocol is developed and maintained as an industry standard. By establishing a uniform set of rules and guidelines, the W3C promotes consistency and interoperability across different web browsers and automation frameworks.
3. JSON Wire Protocol over HTTP: Simplified Communication
The JSON Wire Protocol is a lightweight language used for communication between Selenium scripts and browser drivers. It's based on JSON (JavaScript Object Notation), a format that's easy for both scripts and drivers to understand.
How It Works:
领英推荐
Through the JSON Wire Protocol, Selenium ensures smooth automation across diverse browsers and platforms as it's platform independent, efficient and web friendly.
4. Browsers
This part of the WebDriver architecture is straightforward. Browsers execute commands received from scripts by calling the appropriate methods to perform automation tasks. Supported browsers include Chrome, Firefox, IE, Edge, Safari, Opera, etc.
Automation using Selenium WebDriver Explained
Now, let's peek behind the scenes of automating web applications across different browsers using Selenium WebDriver. We'll illustrate this with some simple commands:
In this example written in Java, the Selenium Client Library helps us craft scripts. Through the JSON wire protocol, the Selenium client communicates with the browser driver (Chrome in our case). It commands the browser to open the TheTestsmith website and click a button.
Subsequently, the Chrome browser driver relays these commands to the browser itself. Upon completing the automation tasks successfully, the response is sent back to the automation script.
And that wraps up our dive into WebDriver architecture in Selenium. Next up in our Test Automation Tutorial series is the setup process. Stay tuned to learn how to set up Selenium on your machine and try out a sample script!