QTP框架--VBS读取QTP运行时参数及运行脚本

上一篇 / 下一篇  2014-10-12 12:03:02 / 个人分类:QTP/UFT

A6O/~p,s0之前是在vb编辑器里直接写死的运行时参数,用Test.AddNewAction 来读取脚本并执行的,改进了下,从excel读取配置,并且使用test.open来打开一个test,通过读取datatable的行来直接运行脚本
T/n&_V8wGc5G0参数表app的参数(sheet:global)51Testing软件测试网q7IDK,lM.xr+t eS

51Testing软件测试网#BLUnB+N0D

参数项参数值说明
qtpvisibleTRUE
addinsWeb加载插件,多个用逗号分隔
runmodeFast运行方式:fast,noraml
viewresultFasle
windowstateMaximized,Minimized,Normal
StepExecutionDelay 3000步骤等待时间(毫秒)
BrowserCleanupTRUE测试完成后,是否关闭浏览器
ImageCaptureForTestResults OnErrorAlways,OnError,OnWarning,Never
51Testing软件测试网4?Iog.@/O n

test的参数(sheet:test)
j3W.G)CLB0

参数项参数值说明
onerrorNextStepNextStep、Stop、NextIteration、Dialog
DisableSmartIdentification是否启用智能标示,启用为否
IterationMode循环方式:oneIteration,rngAll,rngIterations
ObjectSyncTimeOut 3000等待对象加载时间

eH:q1{!W&d"SV0

0R_d!GU piAS:}0test_set
MO0oO's Lh$[0

scriptnameparameterstatusresult
openieurl
loginuname,password
querystring
51Testing软件测试网R2w p/BG

1Y d D$WE s1zB0vbs脚本如下:51Testing软件测试网s8^ J6Ah4} @.E6aeb
Call main()51Testing软件测试网 |Yc%W3m0y/wSb:Y
Dim app,apptest
^pf7?5Ujb0'以下变量需要先定义,不然在function里可能传递不了
7A1D7Q:~Y!C+sN iS w0Dim strrunmode,arraddins,bviewresult,stronerror,blnqtvisible
T\e} q}0Function main()51Testing软件测试网E4Z \:u1G:}6e:YMo7s
 getcfg("d:\config.xls")
a$cf?z e4n0 opentest()51Testing软件测试网'y+n C&Rl?/g
End Function
9nH7]7P;v-y`\0
b#AQsRM%g)t0Function getcfgtodict(filepath,sheetnamre)
Z+aS1t'rP@2\0 Set xcel=CreateObject("Excel.Application")
:| e~n H]0 Set dict=createobject("scripting.dictionary")
#J!^? ]&O'O0 Set book=oexcel.workbooks.open(filepath)
JwLR#cs e2N0 Set sheet=obook.sheets(sheetname)51Testing软件测试网K zh+s+pNN
 intcount=osheet.usedrange.rows.count51Testing软件测试网B b_ {'e
 For i = 2 To intcount Step 151Testing软件测试网a2G(l4{rU^L&bs
     '将配置参数项和值写入数据字典51Testing软件测试网wf#b0X*{
  odict.Add osheet.range("A"&i).value,osheet.range("B"&i).value
B ?#A6[UZi&b?0 Next51Testing软件测试网g%P,b c#n5tM
 Set getcfgtodict=odict51Testing软件测试网|2G;{&b'glm
 Set dict=nothing
v9su Z*j4M9i3P0 Set excel=nothing
J:E)aew&w0End Function
+y zxfY6{N Vo051Testing软件测试网w0ag+HlRL
'从excel读取运行时配置
#yBQ#KF&S0Function getcfg(filepath)
'rg&wij"F0 Set dictcfg=getcfgtodict(filepath,"global")51Testing软件测试网 Eh AvZ5UuJ c
 arraddins=split(dictcfg.item("addins"),",")51Testing软件测试网0\?A}%^)fudCz
 blnqtvisible=dictcfg.item("qtpvisible")
5Dxp`2X@oU0 strrunmode=dictcfg.item("runmode")
!w;q6xP4l"k)kH0 bviewresult=dictcfg.item("viewresult")
0r t/omP@0 51Testing软件测试网 @8x4fW B-vXJ~
 Set dictcfg2=getcfgtodict(filepath,"test")
J:A5k%wj;uJ0 stronerror=dictcfg2.item("onerror")
;N%aU]C-^ ?WoT0End Function

hk6C9n o:Q0

O(h.Ea5]0Function opentest()51Testing软件测试网Y)Md w$K)O P
 Set app=createobject("quicktest.application")51Testing软件测试网-mR,{2A(I
 rt=app.SetActiveAddins(arraddins,errdesc)
'jO'b,f,mq Z0 If not app.Launched Then
8bk+r%wf8hFt)DA*w0  app.Launch
)q sPOT0 End If51Testing软件测试网B8kZ'Ck*E
 'app的参数设置
t5o+`"Hd4S0 app.Visible=blnqtvisible51Testing软件测试网.Vc0Uk}y/ep
 'app.WindowState=Maximized51Testing软件测试网.AH XMV3M
 app.Options.Run.RunMode=strrunmode51Testing软件测试网i+l|v+k
 app.Options.Run.ViewResults=bviewresult51Testing软件测试网 v8x'N.N"sK/E4kx
 'app.Options.Run.StepExecutionDelay=3000
%[Epg g0 'app.Options.Web.BrowserCleanup=true
0F1aHX1KS.{p0 app.Options.Run.ImageCaptureForTestResults="OnError"
d Dir,@Oe9V FAS0B0 '将相关folder加入到测试的folder,以便后面可用相对路径51Testing软件测试网8[LxN9m*Z"g)|
 set fso=createobject("scripting.filesystemobject")
7i X j,h{,ZU0        set fold=fso.GetFolder("d:\test_frame")
1Pa;}/F_c4hR0        set subfold=fold.SubFolders51Testing软件测试网I4b1dp#\ kJur
        for each sb in subfold51Testing软件测试网k9N9qRR5f
        app.Folders.Add sb.path
3FW*P]Bc0        next51Testing软件测试网1aAF^+p)Pb"`,N/H
 'test的参数设置

^g5iId#j-Z0

Y)t4L%O^!z+D0 app.Open "d:\test1"
:]|:f,F1~'\2l0 Set apptest=app.Test51Testing软件测试网yq,c eW"Z
 apptest.Settings.Run.OnError=stronerror51Testing软件测试网,?lK K k&Sy
 'apptest.Settings.Run.DisableSmartIdentification=true51Testing软件测试网+KC'jV6?6yB0e&JD
 'apptest.Settings.Run.IterationMode="oneIteration"
]8Fj"X p0 
2BEz i6uJ(t}%Rv0 '加载函数及datatable51Testing软件测试网_l;f1p;fu"^
 filepath="lib1.qfl|lib2.qfl"
j$oX#P$D"r0 apptest.Settings.Resources.Libraries.Add filepath51Testing软件测试网.~8Po no x(N q S
       '将测试案例的表格直接导入到datatable,每个案例为1个脚本,包含1个function,名称和脚本名称相同,51Testing软件测试网[Zau7z1Z
 apptest.Settings.Resources.DataTablePath="test_set.xls"51Testing软件测试网lU5m#\/va
 '将所有测试脚本加入到函数库51Testing软件测试网$Q!x:Yz'|.N!n
 Set casepath=""51Testing软件测试网&L.jKkSWD+D%F
 set fso=createobject("scripting.filesystemobject")51Testing软件测试网-g\['\,m6d9o1t+[!h
        set fold=fso.GetFolder(casepath)
^5r$\a`*UL/N7Q0        set sfile=fold.Files
l2pF7h:t0        for each sf in sfile
?"oA1nC#OI0        apptest.Settings.Resources.Libraries.Add sf.name
~(FzS5ZFr^n4["S0        next51Testing软件测试网aB9P{]

fH$m7r RluL(^0         apptest.run
'uyGb(J0End Function

+[0B!nKH,z-gx051Testing软件测试网c}uv$``4Tv


a|1Tan&f @r P0test1的脚本

;HwEY5@$wL+b1kQ051Testing软件测试网 ]#G(~K+no5U

On error resume next
)[s&Yw&o{!va0icount=datatable.GetSheet("Sheet1").GetRowCount
@5{ iM{*x0Pw"e1y0datatable.SetCurrentRow 1
c;R \|r4k0For i = icount To 1 Step 1
0]BI6A8Q_G0'直接通过execute来实现脚本的调用及参数传递,如:openie "www.sample.com"51Testing软件测试网)x Hh`0J:hF_ x)Jm~
execute(datatable.Value("scriptname")&space(1)&datatable.Value("parameter"))
U*n `:J0ruJ8F0datatable.Value("status")=reporter.RunStatus
,i+@RU'p@7V-E'{B"W0datatable.Value("result")=environment.Value("ResultDir")
Q k'j%__9h0datatable.Export "test_set.xls"51Testing软件测试网 f(I7ids oG)xO
datatable.SetNextRow
R1Q-Wy(D-o\x0Next51Testing软件测试网G,]q?B7C$g%l

51Testing软件测试网xX5x2\,_c

O1?QOGP0

TAG:

 

评分:0

我来说两句

Open Toolbar