Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

selenium - How does chrome driver interact with Chrome browser?

It says

ChromeDriver is a standalone server that implements the W3C WebDriver standard

It looks like W3C WebDriver standard only defines the interface between the automation program and Chromedriver. Chromedriver act as a HTTP server to get the command from automation program.

But how does ChromeDriver communicate with Chrome?

Still through HTTP protocol?

If yes, where could we get the documentation about the details? And what component inside of Chrome is in charge of handling the command from Chromedriver? Is it built in chrome or just an extension of Chrome?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

At the core of Selenium is WebDriver, which is the remote control interface that enables introspection and control of user agents. WebDriver provides a platform and language-neutral wire protocol as a way for out-of-process programs to remotely instruct the behavior of web browsers, hence instruction sets that can be run interchangeably in many browsers.


Selenium WebDriver refers to both the language bindings and the implementations of the individual browser controlling code and commonly referred as WebDriver. WebDriver is an API and protocol that defines a language-neutral interface for controlling the behaviour of web browsers. Each browser is backed by a specific WebDriver implementation, called a driver. The driver is the component responsible for delegating down to the browser, and handles communication to and from Selenium and the browser.


The Parts and Pieces

At its minimum requirement, WebDriver talks to a browser through a driver and the communication is two way:

  • WebDriver passes commands to the browser through the driver
  • Receives information back via the same route.

ChromeDriver

ChromeDriver is a standalone server that implements the W3C WebDriver standard. ChromeDriver is available for Chrome on Android and Chrome on Desktop (Mac, Linux, Windows and ChromeOS). The driver runs on the same system as the browser. This may, or may not be, the same system where the tests themselves are executing and is the example of direct communication.

basic_comms.png


Remote WebDriver

However, Communication to the browser may also be remote communication through Selenium Server or RemoteWebDriver. RemoteWebDriver runs on the same system as the driver and the browser.

basic_comms_driver_webdriver.png


Selenium Grid

Remote communication can also take place using Selenium Server or Selenium Grid, both of which in turn talk to the driver on the host system.

remote_comms_server.png


Communication through commands

The WebDriver protocol is organised into commands. Each HTTP request with a method and template defined in the specification represents a single command and hence each command produces a single HTTP response. In response to a command, the remote end will run a series of actions known as remote end steps. These provide the sequences of actions that a remote end takes when it receives a particular command.


Command Processing

The remote end is an HTTP server reading requests from the client and writing responses typically over a TCP socket. In the specification the communication is modeled as the data transmission between a particular local end and remote end with a connection to which the remote end may write bytes and read bytes. The exact details of how this connection works and how it is established is a bigger topic and out of scope for this question. After a connection has been established, the remote end must read bytes from the connection until a complete HTTP request can be constructed from the data. If it is not possible to construct a complete HTTP request, the remote end must either close the connection, return an HTTP response with status code 500, or return an error with error code unknown error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...