VB调用QTP

今天帮一个加拿大的朋友解决VB调用QTP的问题,自己写了一个Demo 。

创新互联建站主要从事网站建设、成都做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务靖江,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

下边是源代码

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. ' 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调试通过。


网站标题:VB调用QTP
链接分享:http://bzwzjz.com/article/piejip.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站建设方案 网站设计 成都网站建设 温江网站设计 成都网站制作 企业网站建设 成都响应式网站建设公司 品牌网站建设 自适应网站设计 网站设计公司 营销网站建设 成都响应式网站建设 成都网站制作 企业网站制作 响应式网站设计 成都营销网站建设 手机网站制作 教育网站设计方案 成都网站建设 成都网站制作 成都网站制作公司 成都网站建设公司