QTP脚本的封装和调用

发表于:2009-6-16 13:50

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:cloverlt    来源:百度空间

  把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是可以有返回值的。

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号