QuickTest 几个交换值的方法
上一篇 / 下一篇 2010-09-26 16:16:58 / 个人分类:QTP
注:此文在SOHU一个BLOG里有一份,因为我把用户名忘了,所以那个BLOG就放弃了,并非抄袭。51Testing软件测试网PJdX,tf ZIb
如果这里有可借鉴的东西朋友要转载,请标注一下,谢谢。51Testing软件测试网0DD5a fW5m
8Yf)^ oZ&wW(h0
^J8sh.o,~0最近自动化测试工具QTP做挺多,有些用到的方法拿出来一点点共享,也算自己沉淀一下。
)qX%d"R}051Testing软件测试网'^)v2qk8E6[D~"H
首先一个,测试中可能需要将某些数据存放到全局空间中,这个全局空间我也说不好,就是能让多个Action都取到的地方吧。我目前了解到的:51Testing软件测试网-@r`5R8}H.W
51Testing软件测试网6O&{c(g:f&Xag#HRcW
1)可以存在Action内定义的变量中,作为参数传给下一个调用的Action。
g:Ji;R{0
RoZ M3? g8]\0比如: Action1定义两个参数(右击Action,选择Action Properties,在Parameters选项卡中设置。)51Testing软件测试网!s*IQg4{Z4i
51Testing软件测试网)eZ[Vn(K2Z(n2|o;b8G
调用时在RunAction最后部分把要传的变量写进去就行。51Testing软件测试网T L1t2ee7D
51Testing软件测试网+B}8Am~D8c
在Action中用Parameter(“参数名”)就可以取出来了。
YJ2^8Akx-{j"GAOu"W0
D Z,qb O(c5k051Testing软件测试网 I`7p/{f,J
51Testing软件测试网vtJ(l8Ku w
2)存储在自定义对象或变量中,由QTP的Environment进行引用。51Testing软件测试网%q.o7L gby*ig
UI;eP!rB/BF4?7_3a5b0这里找个我以前参考AdvanceQtp中文档自己写的类及实现。
5[Eq#kI5F`}051Testing软件测试网${m?'HFm
Class OurExcel
2T%w1N8R}1Np0 Private bAleadyInit
*gB BN1k]0 '********************sub Class_Initialize begin**********************
'`/|'b o;D[%u7F.n0 Private Sub Class_Initialize51Testing软件测试网&Xu+J5B_-N"l^
'check whether has a environment variable named Reference_counter.51Testing软件测试网5J/L5A+yAi
'this variable is for storing the number of current reference to "One" object.51Testing软件测试网`eU `$q3a:H
On Error Resume Next
fWQ*b'V"U,Z0 bAlreadyInit = IsObject(Environment("Reference_counter"))51Testing软件测试网.?mku?~/OX
If Err.Number <> 0 Then Environment("Reference_counter")=0
qa]\G0 On Error Goto 0
7nl5t R4q!C r&x:O0
!Cl2E/n&|\)^2c0 'When "new" operation happen, add the counter.
u`1Q/~bS%H:B0 Environment("Reference_counter") = Environment("Reference_counter") + 1
5QO7| o2xd)v051Testing软件测试网ABvUF.v$bGe3D
'Using the feature of QTP, storing the "One" object into environment...51Testing软件测试网J3OGK7[0s
'The environment name is "Excel_Object".
g^,?+V!}R K[0 'a. check whether the variable exist.
vY|B2SK;r]^o0 On Error Resume Next51Testing软件测试网 c'y@vy5Z!r(Hr]
bAlreadyInit = IsObject(Environment("Excel_Object"))
{G(~{ z0 If Err.Number <> 0 Then bAlreadyInit = False 'Environment isn’t even initialized
?3H'Q"li6u2`8_!j0 On Error Goto 0
`O^3CL0 'b. check whether has it's contents.
"d5G;K%V5c{U1@+T0 If bAlreadyInit = True Then51Testing软件测试网9i |I)\-cwZ
If Environment("Excel_Object") is Nothing Then bAlreadyInit = False
3D-}Km3sQt0 End If51Testing软件测试网^z o*aAN|r
'c. If no object found, create.51Testing软件测试网2m9P2d6}$X w
If bAlreadyInit = False Then51Testing软件测试网?xse2H(?m'Wc
'Msgbox "Constrction object."
qXQk?7s#R.g0 Environment("Excel_Object") = CreateObject("Excel.Application")
G-L+~sD{0 End If
k?*fbX.Hu%H`0 End Sub51Testing软件测试网 p HdA.VE@F&G
'********************sub Class_Initialize End**********************
#AT6B2Cs0
如果这里有可借鉴的东西朋友要转载,请标注一下,谢谢。51Testing软件测试网0DD5a fW5m
8Yf)^ oZ&wW(h0
^J8sh.o,~0最近自动化测试工具QTP做挺多,有些用到的方法拿出来一点点共享,也算自己沉淀一下。
)qX%d"R}051Testing软件测试网'^)v2qk8E6[D~"H
首先一个,测试中可能需要将某些数据存放到全局空间中,这个全局空间我也说不好,就是能让多个Action都取到的地方吧。我目前了解到的:51Testing软件测试网-@r`5R8}H.W
51Testing软件测试网6O&{c(g:f&Xag#HRcW
1)可以存在Action内定义的变量中,作为参数传给下一个调用的Action。
g:Ji;R{0
RoZ M3? g8]\0比如: Action1定义两个参数(右击Action,选择Action Properties,在Parameters选项卡中设置。)51Testing软件测试网!s*IQg4{Z4i
51Testing软件测试网)eZ[Vn(K2Z(n2|o;b8G
调用时在RunAction最后部分把要传的变量写进去就行。51Testing软件测试网T L1t2ee7D
51Testing软件测试网+B}8Am~D8c
在Action中用Parameter(“参数名”)就可以取出来了。
YJ2^8Akx-{j"GAOu"W0
D Z,qb O(c5k051Testing软件测试网 I`7p/{f,J
51Testing软件测试网vtJ(l8Ku w
2)存储在自定义对象或变量中,由QTP的Environment进行引用。51Testing软件测试网%q.o7L gby*ig
UI;eP!rB/BF4?7_3a5b0这里找个我以前参考AdvanceQtp中文档自己写的类及实现。
5[Eq#kI5F`}051Testing软件测试网${m?'HFm
Class OurExcel
2T%w1N8R}1Np0 Private bAleadyInit
*gB BN1k]0 '********************sub Class_Initialize begin**********************
'`/|'b o;D[%u7F.n0 Private Sub Class_Initialize51Testing软件测试网&Xu+J5B_-N"l^
'check whether has a environment variable named Reference_counter.51Testing软件测试网5J/L5A+yAi
'this variable is for storing the number of current reference to "One" object.51Testing软件测试网`eU `$q3a:H
On Error Resume Next
fWQ*b'V"U,Z0 bAlreadyInit = IsObject(Environment("Reference_counter"))51Testing软件测试网.?mku?~/OX
If Err.Number <> 0 Then Environment("Reference_counter")=0
qa]\G0 On Error Goto 0
7nl5t R4q!C r&x:O0
!Cl2E/n&|\)^2c0 'When "new" operation happen, add the counter.
u`1Q/~bS%H:B0 Environment("Reference_counter") = Environment("Reference_counter") + 1
5QO7| o2xd)v051Testing软件测试网ABvUF.v$bGe3D
'Using the feature of QTP, storing the "One" object into environment...51Testing软件测试网J3OGK7[0s
'The environment name is "Excel_Object".
g^,?+V!}R K[0 'a. check whether the variable exist.
vY|B2SK;r]^o0 On Error Resume Next51Testing软件测试网 c'y@vy5Z!r(Hr]
bAlreadyInit = IsObject(Environment("Excel_Object"))
{G(~{ z0 If Err.Number <> 0 Then bAlreadyInit = False 'Environment isn’t even initialized
?3H'Q"li6u2`8_!j0 On Error Goto 0
`O^3CL0 'b. check whether has it's contents.
"d5G;K%V5c{U1@+T0 If bAlreadyInit = True Then51Testing软件测试网9i |I)\-cwZ
If Environment("Excel_Object") is Nothing Then bAlreadyInit = False
3D-}Km3sQt0 End If51Testing软件测试网^z o*aAN|r
'c. If no object found, create.51Testing软件测试网2m9P2d6}$X w
If bAlreadyInit = False Then51Testing软件测试网?xse2H(?m'Wc
'Msgbox "Constrction object."
qXQk?7s#R.g0 Environment("Excel_Object") = CreateObject("Excel.Application")
G-L+~sD{0 End If
k?*fbX.Hu%H`0 End Sub51Testing软件测试网 p HdA.VE@F&G
'********************sub Class_Initialize End**********************
#AT6B2Cs0