Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Behind the scenes working of Selenium [closed]

Being a selenium test developer, I always used WebDriver with knowledge that was limited to usage of the tool in developing test scripts. But I am curious to know how WebDriver interacts with a page on a browser internally.

My questions are:

  1. I have read that webdriver interacts directly with the automation engine of the browser instead of executing Javascript like Selenium RC. Does that mean that WebDriver does not execute Javascript interally AT ALL?
    Does that mean that there is more than one way to interact with the DOM? I was believing that Javascript is the only way to access/parse the DOM on a browser.
  2. Selenium RC used proxy to eliminate the problem of same origin policy. How is WebDriver addressing the problem of same origin policy?

  3. WebDriver uses JSON wire protocol. But where in the components of WebDriver is JSON Wire protocol used? Is it used in the drivers of different browsers? Or is it used in the Language Bindings API?

  4. When my code is: WebDriver driver = new ChromeDriver(); driver.get("http://www.google.com"); WebElement searchField = driver.findElement(By.name("q")); searchField.sendKeys("selenium"); How is the DOM accessed by WebDriver when the above code is executed?

It would really help if someone can explain these to me in details. I want to make a community wiki regarding internal working of WebDriver to hopefully help anyone searching for this topic. Thanks in advance!

like image 709
Abhijeet Vaikar Avatar asked Apr 15 '14 05:04

Abhijeet Vaikar


Video Answer


1 Answers

All implementations of WebDriver that communicate with the browser, or a RemoteWebDriver server use a common wire protocol. This wire protocol defines a RESTful web service using JSON over HTTP.

So each WebDriver command is mapped to an HTTP method via the WebDriver service, and then passed on to the HTTP Command Processor to communicate with the browser. The Command responses are returned as HTTP/1.1 response messages via the WebDriver service.

Different drivers, such as the Firefox Driver and the IE Driver, have different implementations to accomplish the above.

The Selenium WebDriver architecture document linked below goes into further details on how these are implemented and how WebDrvier commands flow through to the browser and back. Read section 16.6 for details on the Firefox Driver.

The Architecture of Open Source Applications - Selenium WebDriver
by Simon Stewart (creator of WebDriver, and core contributor to the Selenium project)

Also, details on the The WebDriver Wire Protocol will be helpful in understanding how the HTTP methods are mapped.

like image 67
Faiz Avatar answered Sep 18 '22 12:09

Faiz