(收藏)自启动QTP测试的VBS代码

上一篇 / 下一篇  2007-12-07 14:54:56 / 个人分类:笔记

Ew:m;UK(mi F!I0网上搜到的一遍文章,写得比较综合,基本上看一次就知道自启动的代码怎么用了

](P dC(@I4w U1v4O051Testing软件测试网}t w$\9{

Dim qtApp51Testing软件测试网u6U.s n3H0ql
Dim qtTest51Testing软件测试网*L,a*VZ?d
Dim qtResultsOpt51Testing软件测试网,N N$|"J h,K$uYYe4U
Dim scrīptPath
QC gfe+u5xv!MC q0Dim ResultPath51Testing软件测试网_1n"vN-j)X
Dim qtpLogPath51Testing软件测试网.|m&P Y0I0{;[`

51Testing软件测试网\}DC2?+K Ni

ezscrīptPath = "C:\Test1"51Testing软件测试网 ]NHO6u^f v/iW
ezResultPath = "C:\TestResult"
:i2I ml/tr0qtpLogPath = "C:\autotest.txt"51Testing软件测试网8B8z9_Jv5a S${ t
Set qtApp = CreateObject("QuickTest.Application")51Testing软件测试网z*N"A }:S'Spq

51Testing软件测试网r)aMY J}R'K `jr

Function WriteToFile (str )51Testing软件测试网 Y;L3PD(e g}
   Const ForReading = 1, ForWriting = 2,ForAppending = 8
8e*iA(t(],a O&x,^#}HX.L0   Dim fso, f
7[ w8E3Y0yv+Y~z0   Set fso = CreateObject("scrīpting.FileSystemObject")
-G0`3_,L$b3QuVxg0   Set f = fso.OpenTextFile(qtpLogPath, ForAppending, True)51Testing软件测试网 e n%?0\P"g
   f.WriteLine str51Testing软件测试网kp)`5J)E
End Function

tBN/?7QV051Testing软件测试网&X i1p~/@ S-~

Function doQtpTest()51Testing软件测试网~.Nh#[?/b.r
qtApp.Launch51Testing软件测试网"W~4r v+XOv
qtApp.Visible = True ' Make the QuickTest application visible

},} d5_JIN+@$^0

3T A3mJ4yZFcx0' Set QuickTest run options51Testing软件测试网:F7_*R'Y5S+K&HG
qtApp.Options.Run.CaptureForTestResults = "OnError"
4^8i/L2m#p ]/O!L Y:c0qtApp.Options.Run.RunMode = "Fast"51Testing软件测试网:})Pe,bxg|J2w
qtApp.Options.Run.ViewResults = False

"a:?$io"P!^8Pe051Testing软件测试网(OC`h#b1T$f8v

qtApp.Open ezscrīptPath, True ' Open the test in read-only mode

&j0_!]IoD\g)]0

*_L7p3c%C1Ay0' set run settings for the test51Testing软件测试网k]7|"KPx3_q a1g7h
Set qtTest = qtApp.Test
q4XO pu q0qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2 to 451Testing软件测试网$h.\oh$U0A:S
qtTest.Settings.Run.StartIteration = 251Testing软件测试网;zP-w-Q/Y{+g8i
qtTest.Settings.Run.EndIteration = 4
9n_Gp fSvk*Y}0qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs51Testing软件测试网w|5iGz chd

51Testing软件测试网?T}v!y#GV4Z

Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
:? W/a Ad"z'}b0qtResultsOpt.ResultsLocation = ezResultPath ' Set the results location

dm U4Y O:Z-H i0

4Z/j`"R3] g0qtTest.Run qtResultsOpt ' Run the test51Testing软件测试网 Vj b*EO/XvK
'response.write(qtTest.LastRunResults.Status)51Testing软件测试网RX9T uvh9s7X+U

L2q NM'e!I0'MsgBox qtTest.LastRunResults.Status ' Check the results of the test run51Testing软件测试网J-z*[ K n
'qtTest.Close ' Close the test

/?&td ]sQ;@ykusS0

1E(sLQ5J6j:Bu A0Set qtResultsOpt = Nothing ' Release the Run Results Options object51Testing软件测试网7?TwV0P\X4dD2S(`
Set qtTest = Nothing ' Release the Test object
,j |/m:I$D2pA0Set qtApp = Nothing ' Release the Application object51Testing软件测试网r2{@{{c"?z
End Function

KC s-Bb_M q051Testing软件测试网5G`z8U"l

If (qtApp.Launched  ) Then
XRJEp{Rn&Ya"N_0                qtApp.Test.stop  'stop current test
(d F{Tx^0                WriteToFile(Time&"----QTP is running test! Ant's request stop the current test. The newset vesion test start!----")
[f{ L"{0e1o0                qtApp.Quit         'close qtp
!v#z;yw8Uw0                doQtpTest()51Testing软件测试网/t#^B+F$SdU0n6B

1N+j\;["j F&Qr0Else

*lzt@ x,W} K#U0

jB,_ G,M0h0doQtpTest()51Testing软件测试网d+Wyt6^:A
WriteToFile(Time&"----QTP is running test! The newset vesion test start!----")51Testing软件测试网SR,j"y9c U.r-r&M4U+i
}
I5xt/[)t5}+U:Z0End If

3P6LY9C-J"Rf:r?0

TAG: 笔记

 

评分:0

我来说两句

日历

« 2024-03-12  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 31455
  • 日志数: 33
  • 图片数: 3
  • 文件数: 8
  • 建立时间: 2007-10-10
  • 更新时间: 2011-06-28

RSS订阅

Open Toolbar