This article, unlike most out there on the web, is intended to give you a basic understanding of Webdriver, its origins, and a high-level introduction to how it works behind the scenes, and how it is used in automation testing.
Webdriver is a framework that, without manual efforts, connects directly to the browser. Webdriver uses language bindings to act directly upon elements on the page(DOM), such as buttons or hyperlinks, through JSON wire protocol over HTTP.
If you are using Java + Selenium, the way a Webdriver session is created is with the below syntax:
But if you are using Selenium + Python, the syntax is different:
The language bindings are what enable us to write test automation scripts regardless of the chosen language. Simple :-)
JSON wire protocol → Though Selenium is moving towards W3C protocol, understanding JSON wire protocol is not a bad idea. When we send a command such as driver.get(“url.com”) or any other Selenium command, a Rest API GET/POST call is generated from the client (Eclipse/IntelliJ or any IDE). To be simple, the JSON wire protocol is the list of APIs which convert the commands to a protocol that is sent to the driver. Think of it as a mediator which helps in sending the request and receiving the response. The reference link below will show you the documentation.
Driver: → So far, we’ve discussed that a request will be sent from the JSON wire protocol to the driver. But what is the driver? The driver is something that tells the browser to act on a given command. It sends a request to the browser and returns back the response received. For example, a check is performed to see if a button is present on the page or not. The results of that check come from the browser to the driver. Continuous requests and responses happen between a driver and the browser.
There are a lot of tools in the market built on top of Webdriver as a wrapper. Protractor is one such tool built on top of Webdriver. Think of it as a is a wrapper around Selenium-webdriver, built for Angular applications. Though, it can also be used for non-angular applications as well with few changes to the config file. With Protractor, you no longer have to add waits or sleeps in your tests; it executes the next command when the element is ready to be acted upon.