VB 调用 QuickTestpro 脚本

简介:
今天帮一个加拿大的朋友解决VB调用QTP的问题,自己写了一个Demo 。
下边是源代码
1.新建工程,引入QuickTest Professional 8.0 object library
2.编写代码如下:
Private strScriptName As String
Private strRunScript As String

Private Sub cmdAddScript_Click()
   strScriptName = InputBox("请输入QuickTestPro脚本的路径以及名字", "Select Script")
   lstQtpScript.AddItem strScriptName
   strScriptName = ""
End Sub
Private Sub cmdRunScript_Click()
If strRunScript = "" Then
   MsgBox "please select you want to a running script in listbox"
Else
    Dim qtApp As QuickTest.Application ' Declare the Application object variable
    Dim qtTest As QuickTest.Test ' Declare a Test object variable
    Dim qtResultsOpt As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable
    
    Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
    qtApp.Launch ' Start QuickTest
    qtApp.Visible = True ' Make the QuickTest application visible
    
    ' Set QuickTest run options
    qtApp.Options.Run.CaptureForTestResults = "OnError"
    qtApp.Options.Run.RunMode = "Fast"
    qtApp.Options.Run.ViewResults = False
    
    qtApp.Open strRunScript, True   ' Open the test in read-only mode
    
    ' set run settings for the test
    Set qtTest = qtApp.Test
    qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2 to 4
    qtTest.Settings.Run.StartIteration = 2
    qtTest.Settings.Run.EndIteration = 4
    qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs
    
    Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
    qtResultsOpt.ResultsLocation = strRunScript + "\Res1" ' Set the results location
    
    qtTest.Run qtResultsOpt ' Run the test
    
    'MsgBox qtTest.LastRunResults.Status ' Check the results of the test run
    qtTest.Close ' Close the test
    qtApp.Quit  'Close QuickTestPro
    
    Set qtResultsOpt = Nothing ' Release the Run Results Options object
    Set qtTest = Nothing ' Release the Test object
    Set qtApp = Nothing ' Release the Application object
    strRunScript = ""
 End If
 
End Sub
Private Sub Form_Load()
  strScriptName = ""
  strRunScript = ""
End Sub
Private Sub lstQtpScript_Click()
  strRunScript = lstQtpScript.Text
End Sub
由于不是具体讲vb的使用所以里面如何新建工程等都省略掉了,如果大家有兴趣可以自己找相关书籍学习。
以上代码在vb6.0 winxp sp2调试通过。




本文转自 fish_yy 51CTO博客,原文链接:http://blog.51cto.com/tester2test/139362,如需转载请自行联系原作者
目录
相关文章
|
8月前
Vb之分享错误案例
Vb之分享错误案例
46 0
|
Shell Windows
零基础VB教程043期:如何调用bat批处理登录?
零基础VB教程043期:如何调用bat批处理登录?
188 0
|
安全 Windows
vb得到一个进程的启动参数?
vb得到一个进程的启动参数?
187 0
VB编程:利用CallByName函数对对象进行操作-23
VB编程:利用CallByName函数对对象进行操作-23
152 0
VB编程:FileLen函数获取文件的大小
VB编程:FileLen函数获取文件的大小
309 0
VB编程:利用CallByName函数对对象进行操作
VB编程:利用CallByName函数对对象进行操作
327 0
|
Shell C#
VB实现SHELL扩展之接口参数获取失败探析
前几天有位网友问我用VB实现SHELL扩展的问题,这个问题比较有意思,虽然VB较少使用了,但是用VB开发COM组件还是比较方便的(前几天用EVC开发COM组件,相比起来,用VB还是比较幸福的),所以便进行了深入的研究。
685 0