本文介绍了在Selenium的幕后工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为硒测试开发人员,我一直使用WebDriver,其知识仅限于在开发测试脚本时使用该工具。但我很好奇地知道WebDriver如何与浏览器内部的页面进行交互。



我的问题是:


  1. 我已经阅读,webdriver直接与浏览器的
    引擎进行交互,而不是像Selenium
    RC那样执行Javascript。这是否意味着WebDriver不会全部执行Javascript

    这是否意味着有多种方式与DOM进行交互?我相信Javascript是浏览器访问/解析DOM的唯一方法。

  2. Selenium RC使用代理消除相同来源策略的问题。 WebDriver如何解决相同来源策略的问题?


  3. WebDriver使用JSON线路协议。但是在
    的组件中,WebDriver是否使用JSON Wire协议?是否在不同浏览器的
    的驱动程序中使用?还是用于Language Bindings API?


  4. 当我的代码是:

    WebDriver driver =新ChromeDriver();
    driver.get();
    WebElement searchField = driver.findElement(By.name(q));
    searchField.sendKeys(selenium);

    上述代码执行时,WebDriver如何访问DOM?



解决方案

WebDriver与浏览器进行通信的所有实现,或RemoteWebDriver服务器使用通用的线路协议。此线路协议使用JSON over HTTP定义了一个RESTful Web服务。



所以每个WebDriver命令都通过WebDriver服务映射到HTTP方法,然后传递给HTTP命令处理器与浏览器通信。
命令响应通过WebDriver服务作为HTTP / 1.1响应消息返回。



不同的驱动程序,如Firefox驱动程序和IE驱动程序,具有不同的实现上述。



下面链接的Selenium WebDriver架构文档将详细介绍如何实现这些文档,以及WebDrvier命令如何浏览到浏览器并返回。
有关Firefox驱动程序的详细信息,请参阅第16.6节。





由Simon Stewart(WebDriver的创建者和Selenium项目的核心贡献者)



另外,有关将有助于了解HTTP方法的映射方式。


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 automationengine of the browser instead of executing Javascript like SeleniumRC. Does that mean that WebDriver does not execute Javascriptinterally 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 ofWebDriver is JSON Wire protocol used? Is it used in the drivers ofdifferent 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!

解决方案

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.

这篇关于在Selenium的幕后工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:51
查看更多