微笑着面对每天,善待自己……

QTP脚本的封装和调用

上一篇 / 下一篇  2009-07-10 16:48:28 / 个人分类:资料

  • 文件版本: V1.0
  • 开发商: 本站原创
  • 文件来源: 本地
  • 界面语言: 简体中文
  • 授权方式: 免费
  • 运行平台: Win9X/Win2000/WinXP
QTP脚本封装起来,使其看起来一目了然!

  简单介绍一下方法:

'启动飞机订票系统

Sub flight()

SystemUtil.Run "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"

End Sub

'登录

Sub login()

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

Dialog("Login").WinEdit("Password:").SetSecure "48dda077c740a7e3a91bdb8caff1f6fae5f02d1b"

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

End Sub

'插入订单

Function insertorder()

Window("Flight Reservation").ActiveX("MaskEdBox").Type "111111"

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

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

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

Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "12538   LON   10:24 AM   PAR   12:24 PM   AF     $162.40" 可以以数值代替如2

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

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

Window("Flight Reservation").WinRadioButton("Business").Set

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

Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", Insert Done..., 10000

End Function

'退出

Sub logout()

Window("Flight Reservation").Close

End Sub

  其实就是把脚本按操作分段。然后以过程(SUB.....END SUB)或函数(FUNCTION ....END FUNCTION)进行封装。

  这样的脚本看上去一目了然,易理解也易于管理。

  二、QTP函数过程的调用

  以上面的QTP录制脚本的封装中的脚本为例:

  Call 过程名/函数名

  直接调用过程名/函数名

  也以飞机订票系统为例。调用上面封装的过程/函数:

  flight/call flight

  login/call login

  insertorder/Call insertorder

  logout/Call logout

  1. 调用SUB/FUNCTION方法是一样的……除了CALL调用如果有参数则需要使用括号将参数变量括起来。

  2. SUB与FUNCTION的区别:SUB过程是没有返回值的.但是FUNCTION是可以有返回值的。



TAG:

 

评分:0

我来说两句

evergreen_wang

evergreen_wang

测试因仔

我的栏目

日历

« 2024-04-20  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 29020
  • 日志数: 52
  • 文件数: 6
  • 建立时间: 2009-06-17
  • 更新时间: 2011-05-31

RSS订阅

Open Toolbar