基于ruby+watir的测试应用系列文章(一) 基本原理

    在web测试中目前已经很流行的测试工具基本上都是基于宏录制的,比如qtp,robot等等 录制工作比较麻烦,而且代码后期产生的脚本维护起来代价比较高,因此有国外牛人采用ruby写了一个web测试的框架,简单灵活,非常实用。
    本文主要计划从watir框架的原理到使用方法到实战实例对这个工具做一系列介绍。
    1. what is  watir?
       watir == "Web Application Testing In Ruby" ,A free, open-source functional testing tool for web applications. It is a Ruby library which drives Internet Explorer the same way people do, clicks links, fills in forms, and presses buttons. Watir also checks results, such as whether expected text appears on the page.
Because it’s build on Ruby, you have the power to connect to databases, read data files, export XML and structure your code into reusable libraries.

    2. ruby+watir 测试环境的准备:       watir是基于ruby的一个测试框架,因此使用的前提是安装有相应的ruby库和脚本解释器。 由于ruby是跨平台的,因此ruby+watir测试环境也可以跨平台。但考虑到大多数测试人员都是基于windows来开发自动化测试脚本,因此,本文主要以windos平台下安装为例介绍 测试环境的准备。
  •   下载ruby安装文件
     windows下一般都选择Ruby One-Click Installer for Windows.可以在:http://rubyforge.org/frs/?group_id=167 下载到,安装过程非常简单,此处无需赘述。
  •    安装watir
      最简单的安装方式就是采用gem获取最新版本进行安装,如果没有特殊需求,这种安装方式应该也是最简单的了,在windos 控制台下直接键入:gem watir install 按照提示一路yes 下去 就可以了。
  •  简单的一个sample
# Always Load the Watir library at the top of your script
require 'watir'

#Start IE  and navigate to a given URL
ie = Watir::IE.start('http://news.google.com')    

#or..Attach to an existing IE window by title or url
ie = Watir::IE.attach(:title,'title')
ie = Watir::IE.attach(:url,/regex matching url/)

#Navigate to a different URL
ie.goto("http://mentorweb/")

#Close IE.
ie.close

至此 ,安装就已经完成了,你就可以通过简单的了解 开始编写自己的测试脚本了。
  • some help tools:
Editors:
Scite (A good light-weight editor installed with Ruby - ruby/scite/scite.exe)
RDT   (Eclipse plug-in for Ruby, great if you need a graphical debugger)

Tips for finding/accessing HTML elements:
IE Developer Tool bar (Lets you explore the HTML elements behind the visible elements on a web page by clicking on the elements
FireBug (Excellent FireFox extension for identifying HTML elements while writing scripts.)
WATIR::SupportsSubElements (Watir API for accessing html elements)
    2. watir 基本原理:

    3. why we choose watir:
       watir与目前流行的其他测试工具相比有如下几方面的优势:
       首先是: 开源 全免费  这对一些公司来说就去掉了很多的限制,极大减少了测试投入。而且,可以在框架的基础上设计特定的测试框架或工具。
        其次是功能强大,一方面依赖于ruby语言本身强大的lib能力支持,另一方面框架基础的设计也非常的强大。
        最后是简单易用,这是我感觉最满意的地方,之前看loadrunner或者qtp的脚本,总感觉复杂的代码逻辑让测试人员后期的维护先得非常复杂,但是ruby就简单多了,从实例可以看出,他对底层dom对象的封装非常优雅,我们只需要简单的调用几个api就可以完成一些功能的测试了。
        
     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值