浅谈QTP中的测试对象

上一篇 / 下一篇  2009-07-27 21:43:31 / 个人分类:QTP

  • 文件版本: V1.0
  • 开发商: 本站原创
  • 文件来源: 本地
  • 界面语言: 简体中文
  • 授权方式: 免费
  • 运行平台: Win9X/Win2000/WinXP
在这里介绍一种通过函数的方式来管理和使用测试对象的方法,该方法的思想是基于利用函数来实现的,把要测试的每一类对象通过一个或几个公用的函数来实现,下面通过具体的code来说明,先建立一个 TestObject.qfl的文件,用来模拟对象仓库的功能。

H PonJ0

51Testing软件测试网.T2lmTU

Function getWindow

s?!E*S]9fmc051Testing软件测试网Oa%u#^qK V

    Set win = description.Create
Dn0~CE&z.]6M0    win("class description").value = "window"51Testing软件测试网X n;^\2BkW

x ruSO7X0    Set getWindow = win

,tH PfT"o8X#A0

\#X0B:?9L"A7Cl0\0End Function

7P,Cb l7\e Y?1u#J!w0

R1n\0Z5iBU0Function getWindowByTitle(title)51Testing软件测试网 A!msy"{T&p4j

51Testing软件测试网[$^n(E:YV*u

    Set win = description.Create
R.J~XN m]Rj}7U0    win("class description").value = "window"51Testing软件测试网9J!I,fA?(b G~,G
    win("title").value = title

}S1Set8WcP I0

*~8m`3E_!_@6]0    Set getWindowByTitle = win51Testing软件测试网uRI.UE_*s+L

L0M.qe a H:dC0End Function

iD6Y VNe051Testing软件测试网j7`'Ve\5~

Function getDialog

i5py-l)fM6iJ8Fy051Testing软件测试网4_*Dyr4QiT(S

    Set dia = description.Create51Testing软件测试网.s_h ]4d0o!n
    dia("class description").value = "window"

A` PI!Klb ]051Testing软件测试网$Pxd)tw*]x%x`

    Set getDialog = dia

-Zsy.c!\/[$K5F0

8B {z d%U BI0End Function

Z[-`&B zo051Testing软件测试网NN~'o$T4|H ibt3j

Function getDialogByTitle(title)51Testing软件测试网q~_8SON

5s/V/c8TH#R0    Set dia = description.Create
5xdTO7J(G5zE`0    dia("class description").value = "window"51Testing软件测试网.aT#\~ Nj*@9b kQ V
    dia("title").value = title

mGQk\)w051Testing软件测试网 n:jI3b(s

    Set getDialogByTitle = dia51Testing软件测试网/K%xCR p p

51Testing软件测试网5tAXuC*A\_$N!D_

End Function51Testing软件测试网4n5]R.V)^

\:V7Gg3e:X R&~0Function getEdit51Testing软件测试网0J tj6[;FL

51Testing软件测试网 v7p$C'[#p

    Set edt = description.Create51Testing软件测试网0^W*_U$w,?:G-k
    edt("class description").value = "edit"51Testing软件测试网g9~?H6dE/WJt

51Testing软件测试网KG8Xm3~)pgr

    Set getEdit = edt

5WJ tx U[b q0

&jl ~ B$KM}*?4@R0End Function

d!R fE v\0

L!EWf*u4iOy0Function getEditByText(text)

[#R}.\arI051Testing软件测试网M']o)lLd

    Set edt = description.Create51Testing软件测试网["\r})F4QM
    edt("class description").value = "edit"
&R-Oc;j1G0    edt("attached text").value = text

/~h5F2JS1\8I+m(c051Testing软件测试网l0C*gP)D;O-j!n8U3_l

    Set getEditByText = edt51Testing软件测试网CGWs_v-q4{

51Testing软件测试网'VJoat(`6dME%f

End Function

J0e2[ Q#]~c0

2?2|kB bss(`],[ pND$U0Function getEditByIndex(index)51Testing软件测试网#N/hST&oa5O IC

.?2tRT%md(t%u.Ex(J.a0    Set edt = description.Create
V*w8kym5hB Tk+i Q0    edt("class description").value = "edit"51Testing软件测试网C)@]YRJ2o[eOnp B
    edt("index").value = index51Testing软件测试网pcj#D t5|*a

KE ~(`1?3[0    Set getEditByIndex = edt

:W}/XPFKu0

WB,aD"g3r)wz0End Function51Testing软件测试网r1@q#@6sX"R

Mt4kF0u:E;Q_7d0Function getButton

C8b1iO5fe'Qqq.Y0

J+M:h0ws5MAT0    Set btn = description.Create51Testing软件测试网4^XD }9V
    btn("class description").value = "push_button"

q de6M3o[7^X1o051Testing软件测试网+o+i,Bi t(V8U6R

    Set getButton = btn51Testing软件测试网Q8G%wuQY

d'hQc"z+a8\F0End Function51Testing软件测试网%_4s-F)n9}L3sf*Zt

51Testing软件测试网:C+j9`K8\](AT

Function getButtonByText(text)

x4P \D(n`AO`0

0T1rJ+U-rv0    Set btn = description.Create
TV lgp"wI"S-s0    btn("class description").value = "push_button"51Testing软件测试网7E2k X~C$~3z| A
    btn("attached text").value = text51Testing软件测试网9sYr4O'] ]raJ8bi

51Testing软件测试网7O!W6vb}nUR[

    Set getButtonByText = btn

0AVQ6m9`5]051Testing软件测试网'f{,mh/Q`

End Function

I`;H1n1Ih~ KJ*i0

_ X!mx_3Mxr051Testing软件测试网j r3`.V9c/ih

  我们通过以上这种方式,可以把我们测试项目中用到的所有的测试对象加入到这个“对象仓库”中来,在使用的时候,只需要调用相应的函数即可实现,如下面的coad所示。

\-Z:YR'`"i ~0

n}y(}&C;y0

SystemUtil.Run "fileName","","filePath"
vx(H&rz iV7k0
F!U3?6ENH ]xYL0IfJavaWindow(getWindow).JavaDialog(getDialog).Exist(30) Then51Testing软件测试网_6c(Xkl I/pOc

8DIc$L\0    With JavaWindow(getWindow).JavaDialog(getDialog)
8?(?x5J"a.O w5k051Testing软件测试网)dGO:hEQuNI hM
        .JavaEdit(getEditByText("User Name")).Set "userName"51Testing软件测试网t@&y1UTmj;EG4q
        .JavaEdit(getEditByText("Password")).Set "userPwd"
$qM:x!p*i`0        .JavaButton(getButtonByText("Ok")).Click51Testing软件测试网~MIck9`kxy$y m
    End with
%h'p%W&e*i9mA,b0Else51Testing软件测试网 F v^6|%FT%{7{+]fg
    Reporter.ReportEvent micFail,"lauch error","launch error, please check the application!"
,P!zZ| ^EO!]U0    ExitTest51Testing软件测试网n?-G]v:Fi8n4Z1\(\
End If

)R6m_|x;mq0}Iv051Testing软件测试网/Kx1Q)Cuj

  通过这种方式实现了测试对象的过度复用,更符合自动化测试的思想,在项目的测试过程中,我们只要不断的加入新类型的测试对象即可,关键是这些测试对象基本不需要怎么维护,便可以很好的进行复用,这些对象不仅仅在一个项目中可以使用,只要是同一类型的项目,我们都可以来使用这些对象,而不需要随着不同的项目我们还要去重复的去维护一个个的对象仓库了。这样大大的提高了我们的测试效率,也便于多人集体合作。51Testing软件测试网B[ t8O\zvpJ

TAG:

 

评分:0

我来说两句

Open Toolbar