发布新日志

  • BadBoy 简明手册(转)

    yaya_free 发布于 2008-10-28 10:20:05

    badboy简介

    Badboy监控internet explorer的活动,提供录制/回放功能.

    录制功能:badboy窗口的顶部显示当前是否处于录制状态,如果点击play按钮,badboy自动关闭录制功能,等到play结束后,可以点击recording按钮,继续录制脚本.

         Remark:必须等到上一步的request处理完毕后,才能点击发送下一个request,否则下一个request会作为第一个request的子frame.

     

    基本操作

    1 创建 suites,tests以及steps

    测试与网站的交互过程,可以在逻辑上划分为几个步骤.例如第一个步骤为登陆雅虎邮箱,第二步为浏览收件箱,第三步为发送邮件.每一个步骤可以包含一到多次的网站交互动作.badBoy中点击new step创建新的步骤. <!--[if !vml]--><!--[endif]-->.同理,可以创建suites 以及tests.

         Badboy回放时,一次执行一个step,每执行完一个step,会显示执行结果,用户必须再次点击play按钮后,执行下一个step.

     

    2 自动化测试脚本

    如果不修改脚本,简单的录制回放并不能满足复杂网站的测试.

    复杂网站往往有下面一些测试场景:

    A 页面参数唯一性要求,例如:注册页面,需要对用户的注册名进行唯一性校验.

    B 测试的server地址不同.

    Badboy提供了易用的参数修改方法,仅仅需要双击request或者参数,在弹出窗口内修改.同时badboy提供search&replacing功能来修改脚本中的参数值.

     

    Remark:建议选择linking variables,同一个参数,往往脚本会发送多次,选择linking variables,badboy会查找所有的与参数有关的值.并统一替换.

     

    特点与技术

    1 录制模式

       Badboy提供两种录制模式: request 模式(默认模式) navigation 模式.点击下图N,切换模式.

    <!--[if !vml]--><!--[endif]-->

    Request模式具有如下优点:如果测试的网页模版修改了,不影响脚本的回放.如果需要badboy导出脚本到jmeter进行性能测试,必须选择request模式.同时request模式的缺点如下:request模式需要添加大量的断言来检查页面上的item.

    Navigation模式将会记录网站交互过程中browser中的元素的点击动作.当回放navigation模式脚本时候,不但回放http request,同时badboy会模拟brower中点击动作.navigation模式的缺点是 :无法使用navigation脚本进行性能测试,因为性能测试引擎运行时候不显示任何用户界面,所以无法执行navigation中模拟点击等动作.

    总结:选择navigation模式还是request模式,取决于测试的目的,如果仅仅要求测试功能而不关心界面,request模式无疑为首选.

     

    2 navigation模式

    Navigation录制browser的三种元素如下:

    1 链接点击

    2 按钮点击

    3 其他点击,例如引发javascrīpt的操作.

    3 表单提交

    表单提交是页面中非常重要的部分,有下面一些案例需要注意:

    1 如果页面表单中某些参数是依赖于某些参数的输入,比如field B javascrīpt根据field A的输入值计算,使用request模式将无法录制正确的参数.

     

    2 request模式下,表单中的所有参数都将发送.包括一些预定义的元素.

     

    自动录制form的方法:点击form中某一field,"Ctrl-Alt-f"录制form,如果每次提交的form名字不同的话,可以使用正则表达式来表示: logonForm[0-9]{4}

     

     

    4 断言

    断言是自动化检测的实现手段,badboy提供了两种断言:

    1 content 检查

    检查页面中是否包含指定的text.断言可以使用正则表达式,比如要检查一个正确登陆的例子,需要检查”welcome [A-z0-9]*\.”

    问题:例子,比如”tree frog”browser中显示,html中显示为"tree&nbsp;frog",因为badboy测试实际的html source,因此将找不到这个断言.避免这个问题的方法是在page中高亮显示text,并使用easy assertion button.如果使用复杂断言,需要精确匹配html source中的text.

    5 截屏

    当测试失败时候,截屏是最有效的方法与开发人员沟通.在断言的属性栏中,选择失败是截屏.badboy会截取失败案例的browser.

     

    6 timeout

    可以为每个request设置timeout时间,右键点击à选择属性à选择play标签,设置timeout时间.

     

    7 弹出框

    使用断言检查弹出框,邮件选择断言,打开"Check against Message Boxes"选项.

     

     

    8 Badboyjmeter使用注意事项:

    1 导出jmeter脚本的时候,jscrīpt不被导出,因为jmeter无内迁browser,jscrīpt元素无法执行.

    2 data sources不被导出.

     

    9 快捷方式

    快捷方式如下:

    F2 Toggles Record Mode On/Off

    F3 Displays the search/replace dialog, or searches if the dialog is already open.

    Ctrl-Alt-Right Starts playing from the current item.

    Ctrl-Alt-Space Stops Playing

    Ctrl+F5 Plays entire hierarchy from the current item. (Note: if focus is inside the browser, IE will intercept as "Refresh").

    F6 Single steps (plays next single item in scrīpt.)

    F8 Shows/Hides scrīpt Tree

    F9 Shows/Hides Summary Tab View

    F12 Shows/Hides both scrīpt and Summary Views together (gives browser full window space)

    Ctrl+Enter Replays the item current item in the scrīpt

    Ctrl+Shift+Enter Replays the current step in the scrīpt

    Ctrl+Shift+Left Rewinds the play marker to the previous step.

    Ctrl+Alt+Up Moves the play marker to the previous item in scrīpt.

    Ctrl+Alt+Down Moves the play marker to the previous item in scrīpt.

    Ctrl+L Displays the lines Server Log File related to the most recent browsing activity.

    Ctrl+K Clears all responses from the scrīpt.

    Ctrl+J Attempts to find and edit the source code file for the current page and/or frame that has focus in the browser.

    Ctrl+Shift+J Attempts to find and edit the source code file for the current page and/or frame that has focus in the browser and also adds the URL for the frame to your scrīpt as a Monitored request.

    Ctrl+Shift+M Adds URLs for all frames in the current browser as Monitored requests.

    Ctrl+D Toggles DOM View On/Off for the active window.

    Ctrl+Page Up While in DOM View changes to previous frame in frame list

    Ctrl+Page Down While in DOM View changes to next frame in frame list

    Ctrl+Alt Changes Record Mode temporarily to Navigation Mode while held down

    Ctrl+Alt+N Toggles record mode between Navigation and Request mode

    Ctrl+Shift+D Opens the documentation editor for the item currently selected in the scrīpt Tree.

     by zhuangxiu
  • 如何在 Watir 中识别各种 HTML 对象

    iccer 发布于 2007-11-27 19:16:01

    The HTML Elements that are currently supported include:

    button <input> tags with type=button, submit, image or reset
    radio <input> tags with the type=radio; known as radio buttons
    check_box <input> tags with type=checkbox
    text_field <input> tags with the type=text (single-line), type=textarea (multi-line), and type=password
    hidden <input> tags with type=hidden
    select_list <select> tags, known as drop-downs or drop-down lists
    label <label> tags (including "for" attribute)
    span <span> tags
    div <div> tags
    p <p> (paragraph) tags
    link <a> (anchor) tags
    table <table> tags, including row and cell methods for accessing nested elements.
    image <img> tags
    form <form> tags
    frame frames, including both the <frame> elements and the corresponding pages.
    map <map> tags
    area <area> tags
    li <li> tags

    :id Used to find an element that has an "id=" attribute. Since each id should be unique, according to the XHTML specification, this is recommended as the most reliable method to find an object. *
    :name Used to find an element that has a "name=" attribute. This is useful for older versions of HTML, but "name" is deprecated in XHTML. *
    :value Used to find a text field with a given default value, or a button with a given caption, or a text field
    :text Used for links, spans, divs and other element that contain text.
    :index Used to find the nth element of the specified type on a page. For example, button(:index, 2) finds the second button. Current versions of WATIR use 1-based indexing, but future versions will use 0-based indexing.
    :class Used for an element that has a "class=" attribute.
    :title Used for an element that has a "title=" attribute.
    :xpath Finds the item using xpath query.
    :method Used only for forms, the method attribute of a form is either GET or POST.
    :action Used only for form elements, specifies the URL where the form is to be submitted.
    :href Used to identify a link by its "href=" attribute.
    :src Used to identify an image by its URL.

    * :id and :name are the quickest of these to process, and so should be used when possible to speed up scrīpts.

    Supported Methods by Element



  • watir中对table的操作

    yumjuntest 发布于 2008-06-23 16:14:06

    在Watir中
    对于实例化的$ie对象,我们可以通过以下的两种方式来访问他的Table元素:
    t = $ie.table(:id,"data")
    t = Table.new($ie,:id,"data")
    同样,对于tr和td来说,分别也有以上两种方法:
    tr = $ie.row(:id,"title")
    tr = TableRow.new($ie,:id,"title")
    td = $ie.cell(:id,"name")
    td = TableCell.new($ie,:id,"name")
    Watir中Table,TableBody,TableRow,TableCell这几个类,都提供了一个索引方法"[](index)"来定位其下一层的子元素对象,该方法为实例方法,"index"为传入的参数,索引值从1开始,而非从0开始。
    用法如下:
    以table的第一行,第一个元素为例:
    tr1 = t.[](1)
    td1 = tr1.[](1)
    也可以连续访问:td1 = t.[](1).[](1)
    如果td中还有其他元素,可以通过td的实例方法直接访问,以checkbox为例:
    cb = td1.checkbox(:id,'navigate_id').click

    对于以上所提到的对象,都是从Element继承而来,所以click,enabled?,exists?,fireEvent,flash,focus等方法都直接可以使用。
    如果你的td元素定位准确了,且鼠标响应事件没有错误的话,那么应该能看到点击后的效果。
    建议你先用flash方法定位一下要操作的元素。
    建议多查一下Watir的API Reference http://wtr.rubyforge.org/rdoc/

    我写的代码如下:

    def logOut()
    t=@ie.table(:id,"CoolMenu2menutable")
    @td_logout=t.[](1).[](16)
    end

    先找到Table,再索引TR,再索引到TD

    ===================================================

    t1 = t.[](1).[](1).to_s

    puts t1  # print the cell of 1 row and 1 col

     

     

Open Toolbar