selenium 的介绍

上一篇 / 下一篇  2008-03-31 13:59:40

  • 文件版本: V1.0
  • 开发商: 本站原创
  • 文件来源: 本地
  • 界面语言: 简体中文
  • 授权方式: 免费
  • 运行平台: Win9X/Win2000/WinXP

我应该使用哪种Selenium工具?

考虑如下功能矩阵:

 Selenium
IDE
Selenium
Remote Control
Selenium
Core
Selenium
Core HTA
浏览器支持仅Firefox很多所有仅IE
需要远程安装
支持 HTTPS/SSL是*
支持跨域是*
需要Java
测试结果保存到磁盘
多语言支持仅Selenese很多仅Selenese仅Selenese

* = Selenium RC中实验性的支持

 

浏览器支持:Selenium IDE仅可以在Firefox中工作。Selenium Remote Control直接支持Firefox和IE,此外还支持手动配置很多其它浏览器。Selenium Core几乎可以在任何浏览器中工作,因为它是纯粹的Javascrīpt。Selenium Core HTA可以在IE最高安全等级(特权)下工作,这意味着它仅能在IE下工作。

 

需要远程安装:Selenium Core需要在被测试应用程序(Application Under Test, AUT)的网站内安装,因为同源安全策略,一个阻止进行跨网站脚本访问的安全策略。那意味着你不能坐在那里写一个Selenium Core测试而运行在google.com;如果要那样做,你需要在google.com安装Selenium Core。如果你不能/不会在你的被测应用程序AUT上面安装Selenium Core,不能保证它在AUT相同的服务器上公开可见,那么Selenium Core可能不适合你。

同源安全策略不会限制Selenium IDE,因为它作为Firefox扩展实现;它对于Selenium Core HTA也无效,因为它运行于IE的最高安全级别(特权)上。Selenium RC通过提供一个代理服务器来保证Selenium JS文件看似来自相同的远程服务器,从而符合同源策略;代理服务器欺骗浏览器,让它认为这里的确有像http\://www.google.com/selenium/这样的目录。

 

支持HTTPS/SSL:最新版本的Selenium Remote Control的代理服务器可以支持HTTPS网站(当前所指版本为0.9.0),但是这个支持还是实验性的。参考使用试验性的浏览器加载器

 

支持跨域:同源策略意味着测试一个服务器/域不能操作另外一个服务器/域。这意味着Selenium Core不能处理跨多个不同域的应用程序。
Selenium RC可以处理切换域的问题,但是这个支持是实验性的。参考使用试验性的浏览器加载器获取更多信息。

需要Java:Selenium Core和Selenium IDE直接在浏览器中运行。Selenium RC需要安装Java(运行代理服务器)。注意,虽然Selenium RC需要Java,你也可以用.NET、Perl、Python和Ruby编写你的RC测试,但是你需要Java来运行代理。

 

将测试结果保存到磁盘:Selenium Core不能将任何测试结果写到磁盘上(因为它是用javascrīpt写的,它不允许向磁盘写数据),当然你可以将测试结果发送到另外一台服务器保存。(你可以通过Selenium COre HTA保存测试结果。)Selenium Remote Control提明确供支持运行测试并用多种语言讲测试结果写入磁盘的功能;它还可以为Selenium Core结果处制理服务器。Selenium IDE是一个Firefox扩展,所以当然支持将测试结果存盘。

 

语言支持:Selenium Remote Control允许你用任何语言写测试,包括Java、.NET、Pertl、Python和Ruby。(你还可以为其它语言添加测试的支持。)Selenium IDE和Selenium Core仅支持使用"Selenese"测试, 一种简单的脚本语言。Selenese有一些严格的限制:它没有条件(没有"if"表达式),并且它没有循环(没有"For"表达式)。这会使编写复杂的测试变得困难甚至不可能。

你可以通过这个链接引用该篇文章:http://shmilyfan.bokee.com/viewdiary.17139008.html

 

Selenium Core FAQ

这些是收集起来的关于Selenium Core的常见问题列表。我们鼓励人们丰富这个列表并对列出的内容进行回馈:

  1. Selenium是用来做什么的?
    • 它用来对Web应用程序做功能或系统测试。这些测试有些时候也被称作接收测试/用户测试/集成测试。Selenium不止意味着单元测试
  2. 为什么我不能让Selenium Core在Google上工作? - 我尝试写一个简单的脚本进行google搜索。我遇到了各种各样的问题。它在你那里可以工作么?这是我的测试:
    Test Type  
    openhttp://www.google.com/ 
    typeqtesting tools
    clicksubmitButton 
    • 简单的回答是因为所有浏览器的Javascrīpt引擎内建的跨站点脚本安全策略,你不能编辑其它域内的网页的内容。外部的页可以正确的在test runner窗口中看到,但是Selenium不能查询或者编辑它里面的内容。
      换句话说,你不能在"foo.com"运行selenium来测试和编辑"bar.com"上的值或着电击上面的按钮。所以,在当前的方式下,你不能给google写"脚本"因为你的脚本并没有放在google.com。如果Selenium和你在测试的应用程序在同一个域中,当然,你就不会遇到跨站点脚本安全问题造成的功能限制了。
      • 你可以在这里阅读到更多源于跨站点脚本的问题:开发文档
  3. 我如何在外域或者远程的服务器上运行我的测试脚本,绕过跨站脚本安全问题?
    • 这里有几种方法可以绕过跨站脚本安全(限制):
      • 如果可能,部署将Selenium Core和你的测试部署在你正在测试的应用程序里面。
      • 或者:使用Selenium IDE运行你的自动化测试。Selenium IDE是一个firefox扩展(插件),(它以"chrome" url方式运行)这样它不受浏览器的安全限制。
      • 或者:使用Selenium Remote Control运行你的测试。Selenium Remote Control提供一个配置在客户端的代理,来欺骗浏览器,使其认为应用程序和测试工具(脚本)来自同一个域。
      • 或者:让Selenium作为"HTA"应用程序运行,或者在Internet Explorer中作为"HTML Application"运行。HTA应用运行于与其它受信的客户端应用程序相同的安全上下文中,所以不会受到跨域脚本的安全限制。(你可以在这里得到更多消息:MSDN
      • 还有,请查看相关的问题:"为什么我不能给google.com写脚本"。
  4. 你如何创建测试表格?
    • The developers on the Selenium project use Mozilla Composer to create plain HTML text files for their
      tests. By default, Mozilla Composer writes very clean HTML without any extra, unnecessary markup.
      • You can also useSelenium IDEto write your tests scrīpts.
      • Another option is any text/html editor to create test tables. Future versions of Selenium may support RST (ReStructred Text), or wiki-table syntax, natively. However, you are free to use another format now, as long as you remember to generate the HTML files from your source files, either during your build process or dynamically at run-time.
  5. So I was able to deploy Selenium and my app showed up in the TestRunner, but my tests are failing with no errors, what gives?
    • One thing to check, especially if you are using Nvu, is that the third column in your test table (the optional arguments column) is not an empty cell. A single space or non-breaking space seems to be resolve the issue.
  6. I don't have access to the server where my AUT (application under test) is deployed, does that matter? IE., is physical deployment of app server and testrunner an issue?
    • Physical deployment doesn't strictly matter, but if you can't modify your AUT, you do have to somehow either force the browser to disable the same-origin policy or trick the browser into thinking that your tests and your AUT have the same origin.
  7. Selenium isn't working, where are the diagnostics for problem solving?
    • Look for Javascrīpt errors. (In IE, check for a warning in your browser status bar; in other browsers you'll want to check the Javascrīpt console for errors.) Additionally, try opening the logging window before you run your tests; that may reveal problems. You may also want to try using a Javascrīpt debugger. In Internet Explorer you can configure theMS scrīpt Debugger; in Mozilla you can configureVenkman. (Be aware that there are several versions of Venkman; many of them are not forward/backward compatible with different versions of Mozilla/Firefox. Make sure you get the right one that works on your browser!)
  8. Selenium scrīpts are rather verbose - Is it possible to record these scrīpts to speed things up?
    • Yes, useSelenium IDEThis is a firefox plugin, so it requiresfirefox, but the results can be replayed using any browser you choose once the scrīpt has been created.

你可以通过这个链接引用该篇文章:http://shmilyfan.bokee.com/viewdiary.17139033.html

 

上次讲了如何安装Selenium IDE,现在来讲解下如何来安装Selenium Core

先来介绍下Selenium Core

Selenium Core是一个用来测试Web应用的测试工具。Selenium Core的测试直接运行在浏览器中,就像真实的用户在操作一样。它可以分别运行在WindowsLinuxMacintosh系统的Internet ExplorerMozillaFirefox浏览器中。

浏览器兼容性测试测试你的应用看是否可以在不同的操作系统的不同浏览器上正常工作。同样的脚本可以运行在任何Selenium平台上。

系统功能测试创建回归测试用来检验应用的功能以及用户的满意度。

Selenium Core使用了一个独特的机制让它可以运行在如此多的平台。测试脚本采用纯JavascrīptDHTML写成,你将Selenium Core的测试脚本直接放置到你的应用程序所在的Web服务器中,就可以在客户端使用任何受支持的浏览器运行测试了。

Selenium使用JavascrīptIframe自动化的测试引擎嵌入到你的浏览器中。这项技术应该可以工作在任何启用Javascrīpt的浏览器中。因为不同的浏览器处理Javascrīpt有些不同,所以我们通常不得不调整引擎以便更广泛的支持WindowsMac OS XLinux上的不同浏览器。

下面说下运行Selenium Core需要的环境:

l        Open QA下载最新的Selenium Coreselenium-core-0.8.2.zip

l        把下载的selenium-core-0.8.2.zip解压到你的web服务器中,下面我将在Tomcat中演示。

安装步骤:

第一步:去apache.org下载tomcat安装包。

第二步:正确安装tomcat

第三步:去Open QA下载Selenium Core

第四步:解压Selenium Core包到D:\selenium

第五步:配置tomcat文件,配置一个sc.xml其他配置项为<Context path="/sc" docBase="D:/selenium/selenium-core-0.8.2" debug="0" privileged="true">

第六步:运行tomcat服务

第七步:打开浏览器,输入:http://localhost:8080/sc/

这时你能看到下图界面:

 

这时说明Selenium Core已经运行正常。

我们可以做一个Selenium Core自带的小例子进行测试。

点击Selenium TestRunner进入Selenium Core主界面

 

点击Go,进入Test Suite界面

 

点击左边单个的test case,我们能进入查看和运行相应的单个test。点击中间test case的步骤,能增加或删除断点。测试的应用程序界面,将展示在下部。如下图:

 

下面介绍下下部右边的按钮功能:

l         Execute Tests下四个按钮分别表示运行所有Test Suite、运行选中的Test Suite、暂停或继续、下一步

l        表示运行Test Suite度的快慢

l         Highlight elements选中表示运行的进程将高亮显示

l        Tools下两个按钮分别表示浏览你的界面结构、查看一些错误信息

讲到这里,估计大家都会怎么来初步运行Selenium Core了。Selenium Core的安装就讲到这里。以后再深入来介绍Selenium Core的具体用法。

你可以通过这个链接引用该篇文章:http://shmilyfan.bokee.com/viewdiary.17140234.html

TAG:

lisaangel的个人空间 引用 删除 lisaangel   /   2013-06-26 10:39:25
lisaangel的个人空间 引用 删除 lisaangel   /   2013-06-26 10:39:17
5
 

评分:0

我来说两句

alextowxm

alextowxm

高级测试工程师

我的栏目

日历

« 2024-04-25  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 62095
  • 日志数: 77
  • 文件数: 19
  • 书签数: 1
  • 建立时间: 2007-10-15
  • 更新时间: 2014-03-13

RSS订阅

Open Toolbar