作者:文青山
(rX-Dg6i.C%~Ao0时间:2010-8-30
.S!?%k4@'FpJBZ0标题:我是如何使用QTP去测试的51Testing软件测试网 gO8}\-T9l$}A;k;E'P
注意:请尊重版权!
}(Dod*g&Kk!GP0上接:http://www.51testing.com/index.php?uid-287227-action-viewspace-itemid-21944951Testing软件测试网"D
Qt#v1o^
B、主体脚本过程,此处可使用描述性编程来书写,如使用描述性编程,需从common文件中调用相关的对象库(描述性编程)
"ng"oz"m6Ym0 确定录制的主体过程,此过程我是通过录制实现的,此处代码为测试脚本的主体部分提供基础代码,即为C部分(下方)的扩展操作提供基础代码。51Testing软件测试网/E2oREV(S S(cV
如:
)bk0lh|j
aV5XK0 ‘起动浏览器,进入系统登录界面51Testing软件测试网1L$`"tN#e(Q
'打开IE wqs592452,在不同的机器上需要更改一下51Testing软件测试网M9k
\G|
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe","","C:\Documents and Settings\wqs592452","open"
7N_ cT2^'E6A0Browser("Browser").Navigatehttp://10.9.146.182:8080/index.asp51Testing软件测试网I)?
Gc%\-SS
‘点击登录链接
U{nf"R4_q0Browser("Browser").Page("在线考试系统").Frame("top").Link("【登录系统】").Click51Testing软件测试网*L^3WJ)D la
‘执行登录操作
I{}v:x2H0 Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("uname").Set “123”
/k/O/x(J.B5?0 Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("pwd").Set “123456”51Testing软件测试网9BZm.Lj&c
Browser("Browser").Page("在线考试系统").Frame("main").WebButton("登 录").Click51Testing软件测试网.o|;x8w#G1U5f
'返回登录界面,执行下一轮数据的操作51Testing软件测试网-q w9Qiw:D1D}~
Browser("Browser").Page("在线考试系统").Frame("top").Link("【注销登录】").Click
&O-l|_I0l0 Browser("Browser").Dialog("Microsoft Internet Explorer").WinButton("确定").Click51Testing软件测试网m/y)}:t;c/B'f
Browser("Browser").Page("在线考试系统").Frame("top").Link("【登录系统】").Click51Testing软件测试网t-p4G%l9kpBQ
vh#r7v
C、按照case修改脚本,主要调用库函数中的写入Excel单元格的函数Write_Excel(pathway,sheetname,x,y,content)读取单元格的函数ReadExcelCell(file,sheet,x,y)以及截图函数Qtp_Capture,注意Qtp_Capture应在Write_Excel之前,否则截图时可能为读取Excel的界面
@0^4H$n2M
w h!rqT
P0‘点击登录链接51Testing软件测试网
q
EEE
Ep,IY
1、 '验证loginCase文档中login_001
!Hi!^Kv^4P&GGn0Browser("Browser").Page("在线考试系统").Frame("top").Link("【登录系统】").Click51Testing软件测试网5@RVknWb g
51Testing软件测试网 ~;c.n^
X
Vi+y9hB
‘如果登录后某对象存在,则case文件login_001 Pass,否则Fail,并截图51Testing软件测试网X C-V wV,a@
If Browser("Browser").Page("在线考试系统").Frame("main").WebButton("登 录").Exist Then
!Y.U.qb@}H0 '如果存在此对象,则将case中的actualresults置为pass
W!Ik&?Ju;L0Write_Excel casePath,"login",2,"D","Pass"
cu7ij+N$j:T(D$TE0Else51Testing软件测试网WLPD[K6Cm:Q
'如果出现错误,则截图并保存到指定文件夹中
"]v4HmHg6e0 QTP_Capture capturePath,"login_001"
1AGf;V!\*Lku0d0'如果不存在此对象,则将case中的actualresults置为fail
o'zG&H;F8k0 Write_Excel casePath,"login",2,"D","Fail"51Testing软件测试网
wvA/Rx"t'@\
‘出现错误后,说明错误的原因
#|BP3l1@a0Write_Excel casePath,"login",2,"E","登录系统链接失效"51Testing软件测试网[FkE]|
End If
Bp5m%tR*U9s~#T02、'验证loginCase文档中login_002
`'n,Vx)`,YoQ"](pN0‘利用描述性编程,查看width in characters对象是否存在,并且为3051Testing软件测试网$[l G*@:n#cw#~F+dcrc@
If Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("name:=uname","width in characters:=30").Exist then51Testing软件测试网U?h4B;gOi3w
'如果存在此对象,则将case中的actualresults置为pass51Testing软件测试网,K&wd p$u3O
Write_Excel casePath,"login",3,"D","Pass"
w1t LYt"JA%Ps3`0else51Testing软件测试网-F(M.]c-~xp
'如果出现错误,则截图并保存到指定文件夹中51Testing软件测试网&R
@4u
]t*fb
QTP_Capture capturePath,"login_002"51Testing软件测试网L^)oyxz%M
'如果存在此对象,则将case中的actualresults置为fail
Ia+?L3Hb)a
~:]0 Write_Excel casePath,"login",3,"D","Fail"
D
H(J4_X]lZ#]0 ‘出现错误后,说明错误的原因51Testing软件测试网hSe |(r
Write_Excel casePath,"login",3,"E","用户名输入框未设置为30位"
v)N_:r't5y0end if51Testing软件测试网VR{yOJ]Y`/q
3、’验证loginCase文档中login_003
5a-Gg~n'b0‘利用描述性编程,查看width in characters对象是否存在,并且为3051Testing软件测试网9C uC!{i
|.M-Z@f9o
If Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("name:=pwd","width in characters:=30").Exist then
1Aw$[
y K2{;VO0 '如果存在此对象,则将case中的actualresults置为pass51Testing软件测试网!lt(T3K:\'Qq
Write_Excel casePath,"login",3,"D","Pass"
I B^ Q+lL ZV&?pN&{0else
U |BNySv0 '如果出现错误,则截图并保存到指定文件夹中
_Z(D^y"E0 QTP_Capture capturePath,"login_002"51Testing软件测试网,M;y8H,] g
}0YoH3B
'如果存在此对象,则将case中的actualresults置为fail
R` SS }nW-C-l0 Write_Excel casePath,"login",3,"D","Fail"51Testing软件测试网%g8BVE0G{W
‘出现错误后,说明错误的原因
(Bg3y1}/Zv0 Write_Excel casePath,"login",3,"E","用户名输入框未设置为30位"
yp;o
XkG t3X0end if51Testing软件测试网B9}LzJm W*i,mGf&]
4、 下接:http://www.51testing.com/index.php?uid-287227-action-viewspace-itemid-219451
k0uh `:m1V6K0