Selenium WebDriver Architecture and How it works internally?
In this post we will learn about Selenium WebDriver Architecture and how the selenium works internally .Selenium WebDriver API provides communication facility between languages and browsers.
Selenium WebDriver Architecture
There are four basic components of WebDriver Architecture:
- Selenium client Libraries
- JSON Wire Protocol over http
- Browser Drivers
1) Selenium client Libraries
- Selenium developers have developed language bindings/ Client Libraries in order to support multiple languages
- there are bindings available for a each languages like , Java ,C#, ,Python ,Ruby, PHP, etc. Any tester who has a basic knowledge of working with any programming language can get specific language bindings and can start off.
2) JSON Wire Protocol over http
- JSON Wire Protocol does all the communication between the browser and the code.
- JSON is an open standard for exchanging data on web and It supports data structures like object and array. so it become easy to write and read data from JSON.
- Data is transferred using a RESTful (Representational State Transfer) API using JSON over HTTP.
3) Browser Drivers
- Each browser (supported by selenium) has its own implementation of the W3C standard that Selenium provides each browser has own separate browser driver (browser binaries )
- Drivers communicate with the respective browser and it hides the implementation logic from the end-user
- JSON Wire protocol makes a connection between the browser binaries and the client libraries.
There are multiple browsers supported by selenium which are Firefox , Internet explorer , chrome , opera , Safari etc.
What happens in background when user execute selenium code?
Selenium web-driver gives you an API that will give you access to methods like sendkeys(), getTitle(), findElement() etc.
Below are the actions happen in the background
- For each Selenium command there is an individual HTTP request generates (every command in your script will be converted as a URL) and it passed to the respective browser driver
- The browser driver receives the request through an HTTP server.
For eg ,Client makes http POST requests to the browser driver. findElement, click() are sent as POST request to the browser driver from the client.
- The HTTP server decides which actions need to execute on the real browser.
- The browser follows the instructions as decided in the previous step and executes it.
- The HTTP server receives the execution status and then sends back the status to an automation script, which actually shows the result either passed , fail or error etc.
It is all about Selenium WebDriver Architecture.