声明:本空间的内容不全部是原创,如有雷同只为学习与借鉴之方便,别无它意,来者是朋友,愿通过此平台结交天下测试达狼!

讲解QTP脚本的封装和调用

上一篇 / 下一篇  2010-07-24 09:42:44 / 个人分类:QTP

51Testing软件测试网Ig2K },yK:Hf

QTP脚本封装起来,使其看起来一目了然!
_^iU:j+U0  简单介绍一下方法:51Testing软件测试网(l"Hwv.oDY
  '启动飞机订票系统
&@O!s B/T6v"OW0  Sub flight()51Testing软件测试网 yt7`y$P
  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"51Testing软件测试网5T{5` b#F#kZui
  End Sub
U3i/E6a-W0  '登录51Testing软件测试网CWY WH!Gy+z
  Sub login()
;I)ou4fbJGJ;I _6^0  Dialog("Login").WinEdit("Agent Name:").Set "cff100"
m `)f-h1z+k&X.u0  Dialog("Login").WinEdit("Password:").SetSecure "48dda077c740a7e3a91bdb8caff1f6fae5f02d1b"51Testing软件测试网3sF#jz"o$^ \&wI;z.X \
  Dialog("Login").WinButton("OK").Click
$ro1[D5E0  End Sub
+ov;EH SL/f0  '插入订单51Testing软件测试网e-Z V7L9j__
  Function insertorder()
e5N8|4i)VZi AE0  Window("Flight Reservation").ActiveX("MaskEdBox").Type "111111"51Testing软件测试网)~)xrp g P9F*M`
  Window("Flight Reservation").WinComboBox("Fly From:").Select "London"
4r ker'O!]:U3z0  Window("Flight Reservation").WinComboBox("Fly To:").Select "Paris"51Testing软件测试网 \9c\ }i rG4I7lI;f
  Window("Flight Reservation").WinButton("FLIGHT").Click
ZqV#ESFM"r0  Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "12538 LON 10:24 AM PAR 12:24 PM AF $162.40" 可以以数值代替如251Testing软件测试网A7M;ngF GD)DH5v
  Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click51Testing软件测试网\u)ZK5dq.u2@
  Window("Flight Reservation").WinEdit("Name:").Set "cff100"
l1l q)cW(_5R:f0  Window("Flight Reservation").WinRadioButton("Business").Set
Q)E%]oD%rq0  Window("Flight Reservation").WinButton("Insert Order").Click51Testing软件测试网cfB1hawi!m-fn4\
  Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", Insert Done..., 1000051Testing软件测试网$|o)^&Qa+J7V'G&s3t3G
  End Function51Testing软件测试网V@Z T?`I~ \ ri
  '退出
`#G G:j)b @ HEL0|(e%l0  Sub logout()51Testing软件测试网1xoG5cmp v#ws
  Window("Flight Reservation").Close51Testing软件测试网?T!L:l/et,Z Tf
  End Sub
)B XX!fO}yx0  其实就是把脚本按操作分段。然后以过程(SUB.....END SUB)或函数(FUNCTION ....END FUNCTION)进行封装。
.p9}iue P0  这样的脚本看上去一目了然,易理解也易于管理。
_"r7{w1{[!}Q,^0  QTP函数过程的调用
)o-Z"zYW2w/OP0  以上面的QTP录制脚本的封装中的脚本为例:51Testing软件测试网c$W;K0{"Hl_
  Call 过程名/函数名
ZIvg'Ye0  直接调用过程名/函数名51Testing软件测试网GLU7}k6RH
  也以飞机订票系统为例。调用上面封装的过程/函数:
}eCD,|f0  flight/call flight51Testing软件测试网`J-M#vr
  login/call login
yST/U+Z A^0  insertorder/Call insertorder
9X,_]*M$y&DW O0  logout/Call logout
|1z'^7l`6z5|0  1. 调用SUB/FUNCTION方法是一样的……除了CALL调用如果有参数则需要使用括号将参数变量括起来。
}*Ho(\_q.n(u0  2. SUB与FUNCTION的区别:SUB过程是没有返回值的.但是FUNCTION是可以有返回值的。51Testing软件测试网Ym%g-v] tg

6F8k?*?G0转自http://www.examda.com/soft/zhongji/pingce/20090619/111722995.html

G#X8dp)sV.C0

TAG:

 

评分:0

我来说两句

Open Toolbar