Selenium体系结构的疑惑及解答

发表于:2015-12-03 11:19

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Author chenhengjie12    来源:51Testing软件测试网采编

  一直以来都觉得Selenium只是一个web browser自动化测试框架,但最近实际使用中接触到Appium,Selenium Server等以前没接触过的新的和selenium有关的工具,开始觉得Selenium不仅仅是一个browser自动化测试框架。因此去研究了一下Selenium官网的介绍及其历史。
  疑惑的地方:
  Selenium既然是为了做浏览器自动化测试,为何会有Appium这样的测试手机app的工具?
  Selenium Server、各种浏览器的Driver之间有什么关系?
  Selenium RC又是什么?
  解答步骤:
  Selenium的介绍:
  Selenium automates browsers. That’s it! What you do with that power is entirely up to you. Primarily, it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) also be automated as well.
  简单地说,Selenium能实现浏览器自动化操作。它主要是以测试为目的来自动化web应用,但也可以做其他事情。好吧,这个对解答上面的疑惑没有任何帮助
  Selenium历史
  Selenium first came to life in 2004 when Jason Huggins was testing an internal application at ThoughtWorks. Being a smart guy, he realized there were better uses of his time than manually stepping through the same tests with every change he made. He developed a Javascript library that could drive interactions with the page, allowing him to automatically rerun tests against multiple browsers. That library eventually became Selenium Core, which underlies all the functionality of Selenium Remote Control (RC) and Selenium IDE. Selenium RC was ground-breaking because no other product allowed you to control a browser from a language of your choice.
  While Selenium was a tremendous tool, it wasn’t without its drawbacks. Because of its Javascript based automation engine and the security limitations browsers apply to Javascript, different things became impossible to do. To make things worse, webapps became more and more powerful over time, using all sorts of special features new browsers provide and making this restrictions more and more painful.
  In 2006 a plucky engineer at Google named Simon Stewart started work on a project he called WebDriver. Google had long been a heavy user of Selenium, but testers had to work around the limitations of the product. Simon wanted a testing tool that spoke directly to the browser using the ‘native’ method for the browser and operating system, thus avoiding the restrictions of a sandboxed Javascript environment. The WebDriver project began with the aim to solve the Selenium’ pain-points.
  Jump to 2008. The Beijing Olympics mark China’s arrival as a global power, massive mortgage default in the United States triggers the worst international recession since the Great Depression, The Dark Knight is viewed by every human (twice), still reeling from the untimely loss of Heath Ledger. But the most important story of that year was the merging of Selenium and WebDriver. Selenium had massive community and commercial support, but WebDriver was clearly the tool of the future. The joining of the two tools provided a common set of features for all users and brought some of the brightest minds in test automation under one roof. Perhaps the best explanation for why WebDriver and Selenium are merging was detailed by Simon Stewart, the creator of WebDriver, in a joint email to the WebDriver and Selenium community on August 6, 2009.
  “Why are the projects merging? Partly because webdriver addresses some shortcomings in selenium (by being able to bypass the JS sandbox, for example. And we’ve got a gorgeous API), partly because selenium addresses some shortcomings in webdriver (such as supporting a broader range of browsers) and partly because the main selenium contributors and I felt that it was the best way to offer users the best possible framework.”
  这里已经解答了上面的几个问题。在此说一下这段话的大意:
  Selenium在2004年由Jason Huggins在工作中创造出来。最开始的目的是节省手工重复测试的时间,实现方式是javascript库。
  但随着web技术发展及浏览器对javascript的种种限制,javascript库的结构导致Selenium越来越难以满足自动化测试的需求。
  然后在2006年,Simon Stewart在google创建了WebDriver项目。Selenium在Google中非常普及,但它的局限性让Simon产生让测试工具直接调用浏览器的原生(Native)方法,来打破Selenium的局限性。WebDriver项目就是为了解决Selenium的痛点而创建的。
  然后在2008年,Selenium和WebDriver合并了。合并后的Selenium就是现在大家使用的Selenium2。合并的原因主要是:
  WebDriver解决了Selenium的缺点(例如突破JS沙箱,同时得到了一个清晰的API,也就是今天我们使用的WebDriver API,支持多种语言)
  Selenium也解决了WebDriver的缺点(例如支持大量的浏览器)
  Selenium的贡献者以及Simon本人都觉得融合是最好的方案
  至此,解答了第一个问题:
  问:Selenium既然是为了做浏览器自动化测试,为何会有Appium这样的测试手机app的工具?
  答:这是WebDriver融合后带来的好处。因为WebDriver设计时就是用一套统一的API来驱动不同的平台,因此对于手机app这种有自己原生方法(Appium中使用的是iOS的UIAutomation,Android的UiAutomator或通过Selendroid使用Instrumentation)的应用平台也是适用的。
  Selenium测试套件
  Selenium 2 (aka. Selenium Webdriver)
  Selenium 2 is the future direction of the project and the newest addition to the Selenium toolkit. This brand new automation tool provides all sorts of awesome features, including a more cohesive and object oriented API as well as an answer to the limitations of the old implementation.
  As you can read in Brief History of The Selenium Project, both the Selenium and WebDriver developers agreed that both tools have advantages and that merging the two projects would make a much more robust automation tool.
  Selenium 2.0 is the product of that effort. It supports the WebDriver API and underlying technology, along with the Selenium 1 technology underneath the WebDriver API for maximum flexibility in porting your tests. In addition, Selenium 2 still runs Selenium 1’s Selenium RC interface for backwards compatibility.
  Selenium 1 (aka. Selenium RC or Remote Control)
  As you can read in Brief History of The Selenium Project, Selenium RC was the main Selenium project for a long time, before the WebDriver/Selenium merge brought up Selenium 2, the newest and more powerful tool.
  Now Selenium 1 is deprecated and is not actively supported (mostly in maintenance mode).
  Selenium IDE
  Selenium IDE (Integrated Development Environment) is a prototyping tool for building test scripts. It is a Firefox plugin and provides an easy-to-use interface for developing automated tests. Selenium IDE has a recording feature, which records user actions as they are performed and then exports them as a reusable script in one of many programming languages that can be later executed.
  大意:
  Selenium2(也被称为Selenium Webdriver),是目前主要使用的版本。
  Selenium1(也被称为SeleniumRC, Selenium Remote Control),目前已经被分离出来,且处于维护状态。
  Selenium IDE(Integrated Development Environment)是一个编写用例的原型工具,可以用来协助编写用例原型。
  至此,解答了第三个问题:
  问:Selenium RC又是什么?
  答:Selenium RC是Selenium 1.0版本,现已主要被Selenium2取代,仅处于维护状态。
  WebDriver和Selenium Server
  You may, or may not, need the Selenium Server, depending on how you intend to use Selenium-WebDriver. If you will be only using the WebDriver API you do not need the Selenium-Server. If your browser and tests will all run on the same machine, and your tests only use the WebDriver API, then you do not need to run the Selenium-Server; WebDriver will run the browser directly.
  There are some reasons though to use the Selenium-Server with Selenium-WebDriver.
  ·You are using Selenium-Grid to distribute your tests over multiple machines or virtual machines (VMs).
  ·You want to connect to a remote machine that has a particular browser version that is not on your current machine.
  ·You are not using the Java bindings (i.e. Python, C#, or Ruby) and would like to use HtmlUnit Driver
  大意:
  你并不一定需要Selenium Server,这取决于你如何使用Selenium-WebDriver。如果你只是为了使用WebDriver API,你不需要使用Selenium-Server。需要使用Selenium Server配合Selenium-WebDriver的场景主要有以下几个:
  你使用了Selenium-Grid(可以理解为分布式的Selenium)在多台机器或虚拟机上分发测试
  你希望连接到一台拥有特定的、你目前机器上没有的浏览器版本的远程机器
  你没有使用Java绑定(如Python, C#,Ruby)并希望使用HtmlUnit Driver。
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号