文档章节

Selenium 1.0 vs Selenium 2.0 (Selenium Web-driver)

李长春
 李长春
发布于 2011/07/12 18:58
字数 1060
阅读 1850
收藏 3
Selenium is browser automation tool, for more information select this link.
We already have Selenium1.0, why Selenium2.0?

Selenium1.0 can't tackle following items.
1. Native keyboard and mouse events.
2. Same origin policy XSS/HTPP(S)
3. Pop-ups, dialogs (Basic authentication, Self signed certificates and File upload/download)

Selenium2.0 has cleaner API, webdriver and webelements object, better abstraction.
//Web driver object
browser = webdriver.firefox()
//Web element object, to refer any object on the browser
search_box_google = browser.find_element_name('q')
Support of mobile devices- Android, iOS (Open web testing)
node.JS is server side JavaScript new programming language supported.
I have not seen  Java Docs for Opera and Safari browsers.




Support for different types of mobile testing
1. Emulator.
2. Device connected to workstation.
3. Real device on real location on real network

Improved architecture.
Removing road blocks, hacks and workarounds
Scales up/down.
Selenium2 = Webdriver + Selenium1.0 (merging two different projects)


Lets understand the reason behind merging these two projects.

Selenium 1.0 - You can program in any language, but the prerequisite is that it should support HTTP library.  It initially started as bucket of JavaScript, later Selenium RC(Remote Control) was introduced. RC is a headless Java serer that acts as a proxy server to send commands to to the Selenium Core (JavaScript program that is running in the browser, set of functions). RC receives commands from the test program, interprets them, report back the results of those tests to the test program.  RC consist of Selenium core, that is inject into the browser using client library API when the test program opens the browser. Selenium core interprets the commands coming from the test program and execute selenese commands using browsers built-in JavaScript engine.

Selenium is the first open source browser based testing framework that quickly added support for new browsers as it is written in JavaScript.

Like any large project, Selenium is not perfect. As it is entirely written in JavaScript, which causes significant weakness. Every browser impose very strict security rules on the JavaScript being executed to protect the users from malicious scripts. This make testing harder for some scenarios. For example IE JavaScript security model don't allow to change the value of the INPUT file element for uploading the file and navigating between different domains ( same origin policy) .
As it is a mature product, Selenium APIs has grown over time and it becomes harder to understand how best to use it.

Webdriver project was created by Simon Stewart, it is a clean and fast framework for browser testing automation. Webdriver take different approach for the problems faced by selenium (discussed above). Rather than being a JavaScript application used in the browser, it uses whichever mechanism is most appropriate to control the browser. IE - C++ mainly using automation APIs, Firefox - JavaScript in a XPCOM component (Add-in) ,Chrome - ???.
By changing the mechanism used to control the browser we can overcome the JavaScript security model. When these techniques are not sufficient, Webdiver can use facilities provided by operating System, especially when user want to simulate inputs from the Keyboard and mouse. By using these techniques we are trying to simulate how a real user interact with the browser.
Webdriver had Object Base API when compared with the Selenium which as Directory based approach.
Webdriver JAVA API looks like this.
// 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, search for something
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("selenium");

// And now display the title of the page
System.out.println("Title: " + driver.getTitle());
When these two frameworks are compared side by side, weakness of one framework is addressed by other.
Webdriver support for multiple browsers require lot of effort from the framework developers, where as selenium can be easily extended. Selenium always require real browser, but it can make use of Webdriver HTML unit driver which is very fast and light weight browser that execute in the system memory. Selenium solve most of the common situations in an automation testing, but Webdriver ability to support out side the JavaScript sandbox provides more interesting possibilities. Webdriver don't support parallel testing, where as Selenium has answer by using Selenium GRID (new GRID 2.0 require selenium server). Although this would not solve the limitations of existing Selenium JavaScript, but it would become easier to test broad range of browsers.

Webdriver APIs are used for driving the browsers as per the user requirement, every browser has most natural language "Best Fit" for driving it, so that each developer can develop the driver independently.
But there is a problem, a fix made to one driver don't guarantee that the same fix will resolve the issue in other drivers. Every programmer is good in his own language, Java programmer many not be efficient in writing C++ programs, this create lot of redundant work across the drivers and huge testing activity.
Now the team came up with the concept of Atoms, they have decided to merge the common code across the drivers so that maintenance and development is easy. What will be the common code across all the drivers? Querying the state of browser to find an element and getting attribute values from the page DOM is the major effort across the drivers, the best common language across all the browsers for accessing DOM is by using JavaScript and this is what Selenium Core consist of. Instead of loading the single large JavaScript file into the browser and creating burden on the browser engine. They have decided to break the code into chunks(i.e Atoms), compress the JavaScript with other tools and load it on demand. These atoms are common across all the drivers.
IE browser use C++ as best fit language, how do they pass atoms(JavaScript) to it? I think by placing it in header files.

Following are the drivers available in Selenium2.0 currently
AndroidDriverChromeDriverEventFiringWebDriverFirefoxDriverHtmlUnitDriverInternetExplorerDriverIPhoneDriverIPhoneSimulatorDriverRemoteWebDriver

Name of driver Available on which OS? Class to instantiate
HtmlUnit Driver All org.openqa.selenium.htmlunit.HtmlUnitDriver
Firefox Driver All org.openqa.selenium.firefox.FirefoxDriver
Internet Explorer Driver Windows org.openqa.selenium.ie.InternetExplorerDriver
Chrome Driver All org.openqa.selenium.chrome.ChromeDriver
HTMLUnit driver is a pure Java driver that run in memory without displaying the browser on the screen. It use Rihno as JavaScript engine.

Selenium2 five minutes starting guide
Selenium2 documentation
Selenium2 webdriver new kid

Enjoy using Selenium 2.0 clean API.

© 著作权归作者所有

李长春
粉丝 81
博文 249
码字总数 117406
作品 0
海淀
私信 提问
2.1 Selenium 家族介绍

从图片我们可以看到Selenium已经走过了3大版本,从selenium 1.0 到selenium 3.0 。 这个大版本的变个历程我可以跟大伙简单讲讲: Selenium 1.0 Selenium1.0 源于ThoughtWorks公司,后跟googl...

米阳MeYoung
2018/04/23
0
0
聊聊Selenium不同webdriver的构造

序 本文主要讨论Selenium不同webdriver的构造 Selenium 2.0 Selenium 2,又名 WebDriver,它的主要新功能是集成了 Selenium 1.0 以及 WebDriver(WebDriver 曾经是 Selenium 的竞争对手)。也...

go4it
2017/11/05
49
0
selenium webdriver (python)大全

webdriver的简介 硒2.0的主要新功能是集成的webdriver的API。webdriver的设计除了解决一些seleniumr-RC API的一些限制,与webdriver 的整合,将提供一个更简单,更简洁的编程接口。selenium ...

_周小董
2017/12/02
0
0
python+selenium 自动化测试环境搭建

selenium 是一个web的自动化测试工具,不少学习功能自动化的同学开始首选selenium ,相因为它相比QTP有诸多有点: * 免费,也不用再为破解QTP而大伤脑筋 * 小巧,对于不同的语言它只是一个包...

AltBoy
2017/08/12
0
0
Selenium 2.0rc3 发布,集成测试工具

Selenium 开发团队表示,当发布 2.0rc1 版本时,他们希望这是正式版之前的最后一个版本,但发现了不少反馈的问题,因此有了后来的 rc2,今天,Selenium 发布了 2.0 的第三个 RC 版本,可从这...

红薯
2011/06/27
498
0

没有更多内容

加载失败,请刷新页面

加载更多

计算机实现原理专题--二进制减法器(二)

在计算机实现原理专题--二进制减法器(一)中说明了基本原理,现准备说明如何来实现。 首先第一步255-b运算相当于对b进行按位取反,因此可将8个非门组成如下图的形式: 由于每次做减法时,我...

FAT_mt
昨天
6
0
好程序员大数据学习路线分享函数+map映射+元祖

好程序员大数据学习路线分享函数+map映射+元祖,大数据各个平台上的语言实现 hadoop 由java实现,2003年至今,三大块:数据处理,数据存储,数据计算 存储: hbase --> 数据成表 处理: hive --> 数...

好程序员官方
昨天
7
0
tabel 中含有复选框的列 数据理解

1、el-ui中实现某一列为复选框 实现多选非常简单: 手动添加一个el-table-column,设type属性为selction即可; 2、@selection-change事件:选项发生勾选状态变化时触发该事件 <el-table @sel...

everthing
昨天
6
0
【技术分享】TestFlight测试的流程文档

上架基本需求资料 1、苹果开发者账号(如还没账号先申请-苹果开发者账号申请教程) 2、开发好的APP 通过本篇教程,可以学习到ios证书申请和打包ipa上传到appstoreconnect.apple.com进行TestF...

qtb999
昨天
10
0
再见 Spring Boot 1.X,Spring Boot 2.X 走向舞台中心

2019年8月6日,Spring 官方在其博客宣布,Spring Boot 1.x 停止维护,Spring Boot 1.x 生命周期正式结束。 其实早在2018年7月30号,Spring 官方就已经在博客进行过预告,Spring Boot 1.X 将维...

Java技术剑
昨天
18
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部