`

WebDriver官方介绍

阅读更多

原文地址

WebDriver的介绍以及与Selenium1的区别

WebDriver is a clean, fast framework for automated testing of webapps. Why is it needed? And what problems does it solve that existing frameworks don't address?

For example, Selenium , a popular and well established testing framework is a wonderful tool that provides a handy unified interface that works with a large number of browsers , and allows you to write your tests in almost every language you can imagine (from Java or C# through PHP to Erlang!). It was one of the first Open Source projects to bring browser-based testing to the masses, and because it's written in JavaScript it's possible to quickly add support for new browsers that might be released

[注: Selenium1是基于Javascript,可以支持多个在多个浏览器中运行,并且可以使用多种语言去写脚本]

Like every large project, it's not perfect. Selenium is written in JavaScript which causes a significant weakness: browsers impose a pretty strict security model on any JavaScript that they execute in order to protect a user from malicious scripts. Examples of where this security model makes testing harder are when trying to upload a file (IE prevents JavaScript from changing the value of an INPUT file element) and when trying to navigate between domains (because of the single host origin policy problem).
[注: Selenium1的不完美之处在于同源策略的限制以及JS自身的限制比如说不能用来上传文件]


Additionally, being a mature product, the API for Selenium RC has grown over time, and as it has done so it has become harder to understand how best to use it. For example, it's not immediately obvious whether you should be using "type" instead of "typeKeys" to enter text into a form control. Although it's a question of aesthetics, some find the large API intimidating and difficult to navigate.

[注: Selenium1 API的不易用性]

WebDriver takes a different approach to solve the same problem as Selenium. Rather than being a JavaScript application running within the browser, it uses whichever mechanism is most appropriate to control the browser. For Firefox, this means that WebDriver is implemented as an extension. For IE, WebDriver makes use of IE's Automation controls. By changing the mechanism used to control the browser, we can circumvent the restrictions placed on the browser by the JavaScript security model. In those cases where automation through the browser isn't enough, WebDriver can make use of facilities offered by the Operating System. For example, on Windows we simulate typing at the OS level, which means we are more closely modeling how the user interacts with the browser, and that we can type into "file" input elements.

[注: WebDriver使用了不同的机制去控制浏览器,解除了Selenium1中的JS限制]

With the benefit of hindsight, we have developed a cleaner, Object-based API for WebDriver, rather than follow Selenium's dictionary-based approach. A typical example using WebDriver in Java looks like this:

[注: webdriver拥有更加清晰,基于对象的API]


// Create an instance of WebDriver backed by Firefox
WebDriver driver = new FirefoxDriver();

// Now go to the Google home page
driver.get("http://www.google.com");

// Find the search box, and (ummm...) search for something
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("selenium");
searchBox.submit();

// And now display the title of the page
System.out.println("Title: " + driver.getTitle());

Looking at the two frameworks side-by-side, we found that the weaknesses of one are addressed by the strengths of the other. For example, whilst WebDriver's approach to supporting browsers requires a lot of work from the framework developers, Selenium can easily be extended. Conversely, Selenium always requires a real browser, yet WebDriver can make use of an implementation based on HtmlUnit which provides lightweight, super-fast browser emulation. Selenium has good support for many of the common situations you might want to test, but WebDriver's ability to step outside the JavaScript sandbox opens up some interesting possibilities.

These complementary capabilities explain why the two projects are merging: Selenium 2.0 will offer WebDriver's API alongside the traditional Selenium API, and we shall be merging the two implementations to offer a capable, flexible testing framework. One of the benefits of this approach is that there will be an implementation of WebDriver's cleaner APIs backed by the existing Selenium implementation. Although this won't solve the underlying limitations of Selenium's current JavaScript-based approach, it does mean that it becomes easier to test against a broader range of browsers. And the reverse is true; we'll also be emulating the existing Selenium APIs with WebDriver too. This means that teams can make the move to WebDriver's API (and Selenium 2) in a managed and considered way.

[注: selenium2同时提供webdriver API 与 Selenium1 API]

If you'd like to give WebDriver a try, it's as easy as downloading the zip files, unpacking them and putting the JARs on your CLASSPATH. For the Pythonistas out there, there's also a version of WebDriver for you, and a C# version is waiting in the wings. The project is hosted at http://webdriver.googlecode.com , and, like any project on Google Code , is Open Source (we're using the Apache 2 license ) If you need help getting started, the project's wiki contains useful guides, and the WebDriver group is friendly and helpful (something which makes me feel very happy).

So that's WebDriver: a clean, fast framework for automated testing of webapps. We hope you like it as much as we do!

分享到:
评论

相关推荐

    selenium WebDriver原理介绍

    Selenium WebDriver 是一款广泛使用的自动化测试工具,专为Web应用程序设计。它允许程序员模拟真实用户在浏览器中的操作,如点击、输入、导航等,从而进行功能性和兼容性测试。了解其工作原理对于优化自动化测试脚本...

    selenium2 webdriver中文文档完整

    本文档将详细介绍 Selenium2 WebDriver 的安装、配置、基本操作和使用技巧。 安装 Selenium WebDriver 1. 安装 Firefox:确保 Firefox 安装在默认环境下,不然会报错。 2. 安装 JDK:确保安装了 JDK,我使用的是 ...

    selenium-webdriver介绍PPT

    selenium-webdriver原创selenium-webdriver原创selenium-webdriver原创selenium-webdriver原创

    WebDriver实验版VB6版WebDriver实验,压缩包中有技术文档《WebDriver原理及实验》

    4. **WebDriver API**:介绍VB6中使用的主要WebDriver接口,如`Driver`对象、`WebElement`对象等,以及它们的方法和属性,如`Get`方法用于导航,`FindElementById`或`FindElementByXPath`用于查找页面元素,`Click`...

    webdriver API中文版

    这个中文版文档详细介绍了如何在不同的浏览器上使用 WebDriver,并提供了各种操作页面元素的方法。以下是对这些知识点的深入阐述: ### 第1章:基础设置 1. **下载 Selenium 2.0 的 lib 包**:这是开始使用 ...

    WebDriver命令参考手册

    该手册详细介绍了 WebDriver 的各种命令和协议,旨在帮助开发者更好地理解和使用 WebDriver。 驱动程序 Wire 协议 WebDriver 的驱动程序 wire 协议定义了一个 RESTful web 服务,使用 JSON 过 HTTP 进行通信。该...

    selenium+webdriver中文帮助手册(python版)

    本篇文档将重点介绍如何使用Python版的Selenium WebDriver进行自动化测试。 首先,我们来看看为什么选择Python。Python因其语法简洁明了,学习曲线平缓,深受测试人员和开发者喜爱。在招聘市场中,Python的需求量也...

    selenium webdriver aip部分介绍

    本书是我翻译自,保留了和web测试有关的一些章节,去除了关于移动平台,和BDD的章节。书有所用的代码我是用java来实现的,对于了解了我第一本书初学者指南>的一定代码基础的同学试读这本书会有比较好的入门提高。...

    WebDriver实验版.rar

    VB6版WebDriver实验,压缩包中有技术文档《WebDriver原理及实验》《WebDriver命令编程手册(英文版、中文机翻版)》,代码演示的功能有:操作浏览器自动打开百度、搜索mp3,获得网页源码,获得网页标题,网页截图,...

    selenium+webdriver学习文档

    本文档主要介绍了使用 Selenium+WebDriver 进行自动化测试的学习方法,从基础到精通的学习方法。下面我们将对标题、描述、标签和部分内容进行详细的解释。 标题:selenium+webdriver学习文档 这是一个学习文档,...

    WebDriver实战

    总的来说,本书不仅介绍了Selenium WebDriver的基本概念,还涵盖了安装配置、框架搭建以及实际编写测试脚本等内容,对于想要在IT领域从事自动化测试工作的人来说,是一本非常实用的指南。通过学习和实践,你可以掌握...

    webdriver学习文档

    4. **安装Selenium WebDriver**:访问官方网站(http://seleniumhq.org/download/)下载WebDriver的最新版本,例如Selenium RC 2.21.0。下载后解压缩,并将其库文件添加到Eclipse项目中。这可以通过右键点击项目,...

    Selenium 2 WebDriver 初级视频教程(三)

    Selenium 2 WebDriver 初级视频教程(三) 介绍webdriver 框架中的两个重要接口, WebDriver和WebElement, 其操作是使用WebDriver框架实现自动化测试的基础

    webdriver_firefox_chrome

    本篇将详细介绍"webdriver_firefox_chrome"这一主题,包括WebDriver的基本概念、用途、Chrome WebDriver(ChromeDriver)与Firefox WebDriver(GeckoDriver)的特性以及它们在Selenium框架中的应用。 WebDriver是一...

    selenium webdriver第三版

    《Selenium WebDriver(Python)第三版》这本书深入浅出地介绍了如何利用Python语言来操作和运用WebDriver。 一、Selenium WebDriver简介 Selenium WebDriver是一个开放源代码的API,允许开发人员编写脚本来控制不同...

    chrome webdriver chromedriver(谷歌浏览器selenium驱动包118版本!!!)

    基本介绍: 1、自动化测试:ChromeDriver 常用于自动化测试场景中,开发人员可以使用 ChromeDriver 编写脚本来模拟用户在浏览器中的操作,如点击、填写表单、跳转页面等,以便自动化地执行测试用例。 2、跨平台...

Global site tag (gtag.js) - Google Analytics