VB调用QTP

VB调用QTP,第1张

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

今天帮一个加拿大的朋友解决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. ' 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全部内容,希望文章能够帮你解决VB调用QTP所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1275713.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存