大话人生

  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  299 随笔 :: 0 文章 :: 73 评论 :: 0 Trackbacks

Selenium 参考资料


工具特色

  1. 开发人员,测试人员均可使用的一款测试工具
  2. 支持IE、FireFox等浏览器;测试环境可以和程序代码一同部署于应用服务器下,也可单独搭建。
  3. 用于测试驱动开发TDD、Smoke Test、Regression、Acceptance testing等
  4. 免费、脚本简单(HTML files)、不需要额外的环境
参考Selenium网站:
http://www.openqa.org/
http://selenium.openqa.org/
我应该使用哪种Selenium工具(中文版)?
http://wiki.javascud.org/display/SEL/Which+Selenium+Tool+Should+I+Use 



从Selenium IDE 开始

安装

  1. 安装Firefox
  2. 下载Selenium插件:http://selenium-ide.openqa.org/ 
  3. 将插件拷贝至Firefox/extensions目录下(通常为C:\Program Files\Mozilla Firefox\extensions\)
  4. 重启Firefox,会执行自动安装。
  5. 在“Tools”下能够看到“Selenium IDE”插件安装完毕。

录制

参考录制的小电影:
http://wiki.openqa.org/download/attachments/400/Selenium+IDE.swf


录制好的脚本

Selenium html脚本,又称为Selenese,结构清晰简单:
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Becky02</title>
 </head>
 <body>
 <table cellpadding="1" cellspacing="1" border="1">
 <thead>
 <tr><td rowspan="1" colspan="3">Test02</td></tr>
 </thead><tbody>
 <tr>
     <td>open</td>
     <td>http://www.google.com/</td>
     <td></td>
 </tr>
 <tr>
     <td>type</td>
     <td>q</td>
     <td>ddddddd</td>
 </tr>
 <tr>
     <td>clickAndWait</td>
     <td>btnG</td>
     <td></td>
 </tr>
 <tr>
     <td>assertText</td>
     <td>sd</td>
     <td>Web</td>
 </tr>
 </tbody></table>
 </body>
 </html>

是一个HTML Table:

Test02
open http://www.google.com/
type q ddddddd
clickAndWait btnG
assertText sd Web

HTML Table 由三列构成:
First Column: Selenium command,命令或断言。
Second Column: Target of command,命令或断言的目标(target)。这里可以用多种受支持的组件定位符中的一种来指定目标。通常使用的是组件的 ID 或名称,但 XPath 和 DOM 定位符也是受支持的;
Third Column: Optional parameter,用于为命令或断言指定参数的值。例如,当使用 type 命令时,这一列可能就是一个文本域所期望的值。

参考对于Selenium的命令,请参考网站资源:
http://release.openqa.org/selenium-core/0.8.0/reference.html

 
在selenium core的发布包里,也有此reference,下文中即将提到。
对于自动化测试来说,任何录制/回放工具得到的脚本,都是要进行修改的,这样能够增加脚本的健壮性。将脚本存为html文件。最终的脚本也要至少回放一遍通过才能算完成,在Selenium IDE中,点播放按钮观看放映。



Selenium Core使工作更有条理


下载安装

Selenium Core位于: http://selenium-core.openqa.org/
它是一个zip包,需要应用服务器的支持,此处对于应用服务器的部署等省略,将zip包放入待测试的Web程序下,启动应用服务器,打开 URL:http://localhost:8080/selenium/ ,进入 “Selenium TestSuite”。TestSuite用于将具有类似功能的一些测试用例编成一组,以便它们按顺序运行。TestSuite和Test Cases一样,都是用简单的 HTML 表编写的。Selenium 执行的缺省TestSuite的名称是 TestSuite.html,位于tests文件夹下。


<body onload="filterTestsForBrowser()">

    <table id="suiteTable"    cellpadding="1"
           cellspacing="1"
           border="1"
           class="selenium">
        <tbody>
        <tr><td><b>Test Suite</b></td></tr>
            <tr unless="browserVersion.isSafari" ><td><a href="./events/TestMouseEvents.html">TestMouseEvents</a></td></tr>
            <tr><td><a href="./TestBrowserVersion.html">TestBrowserVersion</a></td></tr>
            <tr><td><a href="./TestJavaScriptAttributes.html">TestJavaScriptAttributes</a></td></tr>
            <tr unless="browserVersion.isKonqueror || browserVersion.isSafari"><td><a href="./events/TestKeyEvents.html">
TestKeyEvents</a></td></tr>
            <tr unless="browserVersion.isKonqueror || browserVersion.isSafari"><td><a href="./TestVisibility.html">TestVisibility</a></td></tr>  
            <tr><td><a href="./TestFramesOpen.html">TestFramesOpen</a></td></tr>
            <tr><td><a href="./TestFramesNested.html">TestFramesNested</a></td></tr>
<!--更多省略,请自行阅读文档-->


以上是一个官方版TestSuite的摘录,参照例子,组织自己的Test Cases,写成TestSuite,放入tests文件夹,便可在浏览器中执行(适用于各种浏览器),例 如:http://localhost:8080/selenium/core/TestRunner.html?test=../tests /myTestSuite.html
值得注意的是:Selenium Core的tests里包含了很多Selenium Command的例子,值得好好研习。

Selenium Core的不足之处

  1. 它需要和应用同时部署于应用服务器之下,在有些项目中并不方便操作。
  2. 它不能将任何测试结果写到磁盘上(因为它是用javascript写的,它不允许向磁盘写数据),当然你可以将测试结果发送到另外一台服务器保存,这就是下文即将介绍的Selenium Core HTA 和 Selenium RC。


Selenium Core HTA


Core HTA 也在Selenium发布包内,仅适用于IE浏览器,不需要远程安装,也不需要Java支持。在命令行里执行命令即可:
C:\selenium\core>TestRunner.hta "test=..%2Ftests%2FTestSuite.html&auto=true&close=true&resultsUrl=results.html&save=true"
根据实际情况修改几个参数,便可执行自己的TestSuite了。
posted on 2009-06-12 15:10 大话人生 阅读(2216) 评论(25)  编辑 收藏 引用

评论

# re: Selenium使用介绍 2009-06-23 13:29 MM
个人觉得waitr比Selenium好用  回复  更多评论
  

# re: Selenium使用介绍 2009-06-30 18:05 大话人生
但是waitr不能够使用在firefox以及sofari  回复  更多评论
  

# re: Selenium使用介绍 2009-07-17 12:28 MM
waitr当然可以在firefox里面用
我没听说Selenium可以再sofari中可以用了  回复  更多评论
  

# re: Selenium使用介绍 2010-07-24 16:09 LawandaBarrett31
Make your own life more easy get the <a href="http://bestfinance-blog.com">loans</a> and everything you want.   回复  更多评论
  

# re: Selenium使用介绍 2010-08-08 06:04 buy essays
Smahing stuff close to this post! In fact, it is good to buy essays to receive the result!   回复  更多评论
  

# re: Selenium使用介绍 2010-08-12 14:47 thesis writing
This can be the great advantage for the dissertation writing service to utilize your good enough theme connected with this good topic for the thesis proposal writing. Hence, all the people will get a possibility to buy the premium quality dissertation cover.   回复  更多评论
  

# re: Selenium使用介绍 2010-08-20 00:15 writer job
The web is really full with the writers job service , which would afford great notes just about this good topic.   回复  更多评论
  

# re: Selenium使用介绍 2013-05-16 01:44 home loans
I took my first loan when I was 32 and that helped my family a lot. But, I need the financial loan once again.   回复  更多评论
  

# re: Selenium使用介绍 2014-03-26 15:07 link
Have no clue which organization to select to receive help from? Go over MarvelousEssays testimonials (essaysreview.com), and make a good choice.  回复  更多评论
  

# re: Selenium使用介绍 2014-04-01 03:29 buy resumes
Are you looking which service to choose for buying resume or where to receive sample of cover letter and professional resume writers review? Or you simply want to buy resume from professional resume writers? Just get in touch with Resume company "perfect-resume.com".  回复  更多评论
  

只有注册用户登录后才能发表评论。