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

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

(gS2dPF`w0之前是在vb编辑器里直接写死的运行时参数,用Test.AddNewAction 来读取脚本并执行的,改进了下,从excel读取配置,并且使用test.open来打开一个test,通过读取datatable的行来直接运行脚本
^E so1A]T V-UZ.r0参数表app的参数(sheet:global)51Testing软件测试网 yN{g&PK]1I{5i

QgCKl*|8lX d|qT0

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

3q8_"?%~+{!O4y0test的参数(sheet:test)
)~i)ySA|H0

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

H0[*B,@Sv!N|cD0

W5w%z/sP)JS,u(K;n,J6J0test_set51Testing软件测试网 Z!K&JfVr9W'F

scriptnameparameterstatusresult
openieurl
loginuname,password
querystring
51Testing软件测试网$A'SE9t2L"B

M}? y/r g)C0vbs脚本如下:51Testing软件测试网7ZV:d7`(U
Call main()
@&X,s#bA`|0Dim app,apptest51Testing软件测试网cI.n3Z&I}
'以下变量需要先定义,不然在function里可能传递不了51Testing软件测试网&_ ^ ^%U-Mr7G(P
Dim strrunmode,arraddins,bviewresult,stronerror,blnqtvisible
%Q$[vZ;TP-D nw0Function main()
w2r)XvD#E#dv[0 getcfg("d:\config.xls")51Testing软件测试网jA:tPXh/T0wE L
 opentest()
/g%wE2H @ _0End Function
hB#ZvXT X0
(f O&nk,Xoyf"KY q0Function getcfgtodict(filepath,sheetnamre)51Testing软件测试网wY|"_8f8~i D
 Set xcel=CreateObject("Excel.Application")
'vGinRc)p0 Set dict=createobject("scripting.dictionary")
,M2c^7b:b5Q W0 Set book=oexcel.workbooks.open(filepath)
Za1AL8b&^0 Set sheet=obook.sheets(sheetname)51Testing软件测试网kJ?"R%x?Y
 intcount=osheet.usedrange.rows.count51Testing软件测试网%u3kq)tJ;Y,Y
 For i = 2 To intcount Step 1
6o)F0gw0R0     '将配置参数项和值写入数据字典
9~~;VC o#b0  odict.Add osheet.range("A"&i).value,osheet.range("B"&i).value51Testing软件测试网,C,z.pg'mv`
 Next
c1k:iOc kr7h0 Set getcfgtodict=odict51Testing软件测试网8L M3Ouw iM(u
 Set dict=nothing
tWDs1_vP8T3\u-ns0 Set excel=nothing
;V/x&^ }#\,D0End Function
-R:U7e"zN051Testing软件测试网8zw%|lO
'从excel读取运行时配置51Testing软件测试网9e Y&U*yqH*j+}H*]W
Function getcfg(filepath)51Testing软件测试网K8WV,Pl9c'g]
 Set dictcfg=getcfgtodict(filepath,"global")
H?e8Qh0 arraddins=split(dictcfg.item("addins"),",")51Testing软件测试网8M#Q_*Y0Lp kNL
 blnqtvisible=dictcfg.item("qtpvisible")51Testing软件测试网A(Y ITE8l
 strrunmode=dictcfg.item("runmode")
Y)ON/Qcf7H)T~0 bviewresult=dictcfg.item("viewresult")51Testing软件测试网Mlw+S/S1X` Q
 
w5m'k iuDB|0 Set dictcfg2=getcfgtodict(filepath,"test")
GSn"b(NS)P!V0 stronerror=dictcfg2.item("onerror")51Testing软件测试网D2v"KX0k\
End Function51Testing软件测试网2d ]~,KH@2F Jh

51Testing软件测试网"]q)aE0t

Function opentest()51Testing软件测试网Q ]/J-nC(FB
 Set app=createobject("quicktest.application")51Testing软件测试网$};g2B9L+H0o
 rt=app.SetActiveAddins(arraddins,errdesc)51Testing软件测试网 r2U"LS&c
 If not app.Launched Then51Testing软件测试网T&]6dw!Xi
  app.Launch
$w,K7CB3Q Ogo/q ?t0 End If
/Q+cRs"apD?0 'app的参数设置
)`QJZl9nk?dJh%E0 app.Visible=blnqtvisible
3yF9H4^e{0 'app.WindowState=Maximized
.}ha"V(LV[G0 app.Options.Run.RunMode=strrunmode51Testing软件测试网-MuC:B9l?1Q
 app.Options.Run.ViewResults=bviewresult51Testing软件测试网*kG_6a#]Y+r7~b
 'app.Options.Run.StepExecutionDelay=3000
CEU_;y(o!f0 'app.Options.Web.BrowserCleanup=true
h z}1z~s3UM1_0 app.Options.Run.ImageCaptureForTestResults="OnError"
n#P\lW7] T:K0 '将相关folder加入到测试的folder,以便后面可用相对路径51Testing软件测试网 a0I6JJ-Z.dj
 set fso=createobject("scripting.filesystemobject")
PSgo.?qL&U0        set fold=fso.GetFolder("d:\test_frame")51Testing软件测试网N%QE]rJa:p
        set subfold=fold.SubFolders
3z/a MRx0        for each sb in subfold
}%{~W2BK0        app.Folders.Add sb.path51Testing软件测试网\U;UKJu
        next51Testing软件测试网c&V%L U)ZGL Y
 'test的参数设置51Testing软件测试网!g}9C&dp7@W

d/}%N+Q`d0 app.Open "d:\test1"
r2W&\1lL i0 Set apptest=app.Test
-FzI0H/D)ZhE0 apptest.Settings.Run.OnError=stronerror51Testing软件测试网/[.R;e4~*@'{4e3G _
 'apptest.Settings.Run.DisableSmartIdentification=true
xAS&lt0 'apptest.Settings.Run.IterationMode="oneIteration"
:?gj{]\0 51Testing软件测试网5@1D8j3o*z4s
 '加载函数及datatable
-^m3W"{u1s%m2BI0 filepath="lib1.qfl|lib2.qfl"51Testing软件测试网{Ak(lN:o
 apptest.Settings.Resources.Libraries.Add filepath51Testing软件测试网0ec;g$U1G r2k;A
       '将测试案例的表格直接导入到datatable,每个案例为1个脚本,包含1个function,名称和脚本名称相同,
7r |*s5C@6r0 apptest.Settings.Resources.DataTablePath="test_set.xls"
1qv)XQ9@!Z0 '将所有测试脚本加入到函数库
LZc \cc8wv0 Set casepath=""
W1r0cq7Nd4n)Pw{ Dk5h w0 set fso=createobject("scripting.filesystemobject")51Testing软件测试网.X9OK!mDu&^
        set fold=fso.GetFolder(casepath)
s\9\&lx+vsP0        set sfile=fold.Files51Testing软件测试网i ?:j5i5A)k`
        for each sf in sfile
7J&a7q3iA0        apptest.Settings.Resources.Libraries.Add sf.name
#[?L$wFf| Q0        next

w6S1LR+EdKY x0

@ ^ D5zuO F c0         apptest.run
*`(~[V^L$F&L0End Function51Testing软件测试网,W bVz$j3QW s-j

.Yf"V5Fha0
M7O4mg}h ~ QD0test1的脚本51Testing软件测试网(r__ ~Q2b7e0d4bK:{

51Testing软件测试网` sS4~~oqH q

On error resume next
R-H cPv`XUQ}0icount=datatable.GetSheet("Sheet1").GetRowCount51Testing软件测试网7l-jC(Xzs_2zR,k
datatable.SetCurrentRow 1
6Y&Kk@D7\0For i = icount To 1 Step 151Testing软件测试网Uanx*Z`Jd
'直接通过execute来实现脚本的调用及参数传递,如:openie "www.sample.com"51Testing软件测试网 Z8w5qKAt;l1\Q
execute(datatable.Value("scriptname")&space(1)&datatable.Value("parameter"))
Dx2RQ)h:Cdv"\ F0datatable.Value("status")=reporter.RunStatus
Dph!g1e4t0datatable.Value("result")=environment.Value("ResultDir")51Testing软件测试网3@Db\{E(\$@
datatable.Export "test_set.xls"51Testing软件测试网'J'x-Z:KAEU(lV
datatable.SetNextRow51Testing软件测试网gV4M9the
Next

U'] ]9hL:w0
51Testing软件测试网!YXz0l\5}

2]JT#ZJ B XNa0

TAG:

 

评分:0

我来说两句

Open Toolbar