`

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工作原理的介绍,原理相关描述

    selenium2 webdriver中文文档完整

    selenium2 webdriver的介绍 selenium2 webdriver的配置安装 selenium2 webdriver的基本操作 selenium2 webdriver使用技巧 ……

    selenium-webdriver介绍PPT

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

    selenium webdriver aip部分介绍

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

    Selenium-Webdriver系列教程

    本文中所以代码和示例均由Ruby编写,本文介绍的webdriver api也主要是ruby binding。所以首先请确保ruby语言在开发环境上正确安装。 教程的第一节从selenium 2.0和webdriver关系说起。 Selenium 2.0 和webdriver之间...

    WebDriver实验版.rar

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

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

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

    Selenium2.0+Webdriver学习【2】

    Selenium2.0+Webdriver学习,介绍了Selenium2.0,并举例,很好的资料

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

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

    watir-webdriver谷歌浏览器驱动

    ChromeDriver 是一款以 ...不熟悉 WebDriver 的用户可以参考 2009 年的项目发布介绍。简而言之,WebDriver 提供基于对象的 API,可以以真实用户的视角测试 web 应用,如点击页面中的元素,或是在文本框中输入内容。

    Selenium2.0+Webdriver学习【1】

    Selenium2.0+Webdriver学习,介绍了Selenium2.0,并举例,很好的资料

    Web自动化测试之Webdriver(python)

    较全面地介绍了selenium webdriver的用法,对完善代码架构、实现自动化测试项目化有不小帮助

    webdriver_guide_java

    webdriver_guide_java,WebDriver 实用指南,for 乙醇,selenium3.0 webdriver使用介绍,包含所有常用操作,附带demo

    Selenium WebDriver automation testing

    Selenium 私房菜,系统的介绍WebDriver,比较全面的一本selenium的自动化书籍

    模数介绍rModulo de introduccion a SeleniumWebDriver_driver_驱动_下载

    模数介绍rModulo de introduccion a SeleniumWebDriver_driver_驱动_下载

    Selenium2.0+Webdriver学习【3】

    Selenium2.0+Webdriver学习,介绍了Selenium2.0,并举例,很好的资料

    webdriver编程入门

    对webdriver的原理进行了简要介绍,并附有大量实例,适合新手入门

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

    Selenium 2 WebDriver 初级视频教程(二) 项目的相关的Jar包及TestNG介绍

    selenium_webdriver学习

    适合于selenium 初学者,里成包含driver使用介绍,页面所有常用元素声明及调用方法,比较齐全,对于selenium 初学者比较适用

    Webdriver项目实践

    具体讲解了用自动化工具selenium录制后脚本转化为webdriver的实例,并讲解了如何使用maven新建一个selenium-webdirver项目,如何在Eclipse中导入新建webdirver的项目,Testng工具介绍及其使用

Global site tag (gtag.js) - Google Analytics