软件测试技术博客,希望大家多提意见

发布新日志

  • QTP中使用with简化代码

    2011-03-15 13:50:12

    QTP脚本开发过程中,可以使用with语句来简化代码。

    With 语句通过将连续语句与相同的父层次分到一组。默认情况下,with选择是不启动的,也就是录制时,QTP不会自动加入该语句,若要启动自动添加with功能,选择选择“tools>Options>General”,勾选“Automatically generate "With" statements after recording

    比对:

    勾选前:

    Dialog("Login").WinEdit("Agent Name:").Set "mercury"

    Dialog("Login").WinEdit("Password:").SetSecure "4d7efbf62bc8a280d9a4600245d218b1fe1b6553"

    Dialog("Login").WinButton("OK").Click

    Window("Flight Reservation").WinObject("Date of Flight:").Click 2,8

    Window("Flight Reservation").WinObject("Date of Flight:").Type "122411"

    Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt"

    Window("Flight Reservation").WinComboBox("Fly To:").Select "London"

    Window("Flight Reservation").WinButton("FLIGHT").Click

    Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "13552   FRA   08:00 AM   LON   08:45 AM   SR     $164.50"

    Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click

    Window("Flight Reservation").WinEdit("Name:").Set "test"

    Window("Flight Reservation").WinButton("Insert Order").Click

    Window("Flight Reservation").Close

     

    勾选后:

    With Dialog("Login")

             .WinEdit("Agent Name:").Set "mercury"

             .WinEdit("Password:").SetSecure "4d7efc61842c44fa533b96c8981187a0d9887eff"

             .WinButton("OK").Click

    End With

    With Window("Flight Reservation")

             .WinObject("Date of Flight:").Click 5,5

             .WinObject("Date of Flight:").Click 3,5

             .WinObject("Date of Flight:").Type "112411"

             .WinComboBox("Fly From:").Select "Frankfurt"

             .WinComboBox("Fly To:").Select "Los Angeles"

             .WinButton("FLIGHT").Click

             With .Dialog("Flights Table")

                       .WinList("From").Select "20324   FRA   09:12 AM   LAX   04:23 PM   AA     $112.20"

                       .WinButton("OK").Click

             End With

             .WinEdit("Name:").Set "test"

             .WinButton("Insert Order").Click

             .Close

    End With


     

    如果录制过程中,没勾选自动生成功能,而录制完成后,又想使用该功能,那么可以使用“Edit >advanced >Applywithto script…”

    同样,如果不想使用该语句,那么可以对已经使用的with进行删除,使用“Edit >advanced >Removewith to script…”
  • 关键字驱动测试(keyword-driven)

    2011-03-15 09:18:00

    部分内容引自网络和《精通QTP与自动化测试框架设计实战》


    原理及特点

    1.        关键字驱动测试,也称为表格驱动测试方法;

    2.        主要关键字包括三类:被操作对象(Item)、操作(Operation)和值(value),用面向对象形式可将其表现为Item.Operation(Value)

    3.        将测试逻辑按照这些关键字进行分解,形成数据文件。

    4.        用关键字的形式将测试逻辑封装在数据文件中,测试工具只要能够解释这些关键字即可对其应用自动化

    5.   将测试从繁杂的测试编程简化至对测试步骤的维护,使自动化测试变的相对容易一些

     

    对象/关键字

    对象:某种可被人感知的事物

    QTP使用过程中,待测试程序中,我们所能识别出的功能,我们即可称为对象

     

    属性:标识对象的特征,也就是让我们能正确识别出对象的特点。

     

    关键字:

    能标识出待测试对象的特征,称之为关键属性

    关键字识别涵盖两个部分:

    1)关键对象

    2)关键属性

     

    优缺点

    适合哪些没有编码基础的人使用

    优点:

       测试的创建及维护阶段更加有效,且结构清晰;

       测试脚本的可读性更强、更易于修改

    缺点

       需要较长的时间

       缺乏更强大和更灵活的编码支持。

  • QTP菜单栏中的子菜单项不显示

    2011-03-11 16:51:20

    QTP中,有时候会碰到菜单栏中的子菜单项不显示的情况,如图所示:

    当遇到这种情况时,可以在“导航栏”区域点击右键,选择“Customize”,在打开的窗口中切换到“Toolbars”标签,点击“Restore All”恢复所有的菜单即可

     

Open Toolbar