Testing UFT未在测试运行后以编程方式关闭/退出

Testing UFT未在测试运行后以编程方式关闭/退出,testing,vbscript,automated-tests,hp-uft,Testing,Vbscript,Automated Tests,Hp Uft,我正在UFT中运行自动测试套件,该套件通过VB脚本调用。问题是,在测试运行后,VB脚本无法以编程方式关闭UFT VB脚本: Dim Test_path Test_path = Script_Name On Error Resume next Dim qtApp 'As QuickTest.Application ' Declare the Application object variable Dim qtTest 'As QuickTest.Test ' Declare a Test obje

我正在UFT中运行自动测试套件,该套件通过VB脚本调用。问题是,在测试运行后,VB脚本无法以编程方式关闭UFT

VB脚本:

Dim Test_path
Test_path = Script_Name
On Error Resume next
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test 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.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False
qtApp.Open Test_path, True ' Open the test in read-only mode

' set run settings for the test
Set qtTest = qtApp.Test

'set result settings
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") 
qtResultsOpt.ResultsLocation = Location

' Run Tests
' THIS IS WHERE I TELL UFT TO RUN TESTS
' AND THE CONTROL NEVER COMES BACK TO VB SCRIPT
' UFT RUNS TESTS AND STAYS IDLE
qtTest.Run qtResultsOpt

qtTest.Close
qtApp.quit
我正在从命令行运行VB脚本,句柄永远不会返回到命令提示符


知道如何使UFT在执行测试后关闭吗?

在关闭或退出后尝试将qtApp设置为nothing如果没有响应,如果要将句柄返回到命令行,可以使用wscript.shell对象的appActivate方法(使用窗口名)。希望这有帮助,因为这行

qtTest.Run qtResultsOpt
仍然没有完成(我猜您的运行可能是在一个测试中循环调用另一个测试),所以您不能将其中断到下一行

尝试将脚本拆分为两个.vbs文件。其中一个启动QTP&running,另一个是主脚本将调用它并执行其他操作

Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")
objShell.Run "..\LaunchAndRunQTP.vbs"
Set objShell = Nothing

希望有帮助。

如果我注释掉测试运行
qtest.run qtrestsopt
,那么VB脚本运行正常,控件返回,VB成功关闭UFT。位置正确吗?我在这条语句中指的是位置-qtrestsopt.ResultsLocation=Location。您的脚本在逻辑上似乎是正确的。我在这里看不到任何问题。这是我也有的。还有一个问题…qtp测试运行正常吗?但一旦测试运行,它就不会关闭它。是rt吗?是的,位置正确地指向了正确的路径,结果确实是在这个位置生成的。是的,测试运行正常,但它不会关闭UFT测试后运行,VB脚本会无限期地运行。请对“On Error Resume next”语句进行注释。检查关闭测试时是否抛出错误。因为qtTest.Close应该是关闭的。如果它不关闭,可能会抛出一些运行时错误。错误恢复下一步只是隐藏错误。