我正在尝试创建一个任务,该任务将运行脚本以每天运行UFT(统一功能测试)。我的脚本正确启动UFT运行完成并提供我在Powershell中验证的退出代码。这是VBS脚本:
testResourcePath = "D:\testnow\code\"
'Getting the test path
Dim objArgs
Set objArgs = wscript.Arguments
testPath = objArgs(0)
'Determining that the test does exist
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
DoesFolderExist = objFSO.FolderExists(testPath)
Set objFSO = Nothing
If DoesFolderExist Then
Dim uftApp 'Declare the Application object variable
Dim uftTest 'Declare a Test object variable
Set uftApp = CreateObject("QuickTest.Application") 'Create the Application object
uftApp.Launch 'Start QuickTest
uftApp.Visible = true 'Make the QuickTest application visible
'Associating function libraries
uftApp.Open testPath + "\fakepath", False, False
Set objLib = uftApp.Test.Settings.Resources.Libraries
'If the library is not already associated with the test case, associate it..
If objLib.Find(testPath + "\fakepath\ErrorHandlingLibrary.qfl") = -1 Then ' If library is not already added
objLib.Add testPath + "\fakepath\ErrorHandlingLibrary.qfl", 1
objLib.Add testPath + "\fakepath\ObjectDefinitionLibrary.qfl", 1
objLib.Add testPath + "\fakepath\TestFunctionLibrary.qfl", 1
objLib.Add testPath + "\fakepath\UtilityLibrary.qfl", 1
End If
'uftApp.Open testPath, False 'Open the test in read-only mode
Set uftTest = uftApp.Test
Set uftResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
uftResultsOpt.ResultsLocation = testResourcePath ' Specify the location to save the test results.
uftTest.Run uftResultsOpt,True 'Run the test and wait until end of the test run
Dim returnCode
If uftTest.LastRunResults.Status = "Failed" Then
'qtTest.Run 'Run the test
uftTest.Close 'Close the test
returnCode = 1
Else
returnCode = 0
End If
uftTest.Close 'Close the test
uftApp.Quit
WScript.Echo "Closing Test"
Else
'Couldn't find the test folder. That's bad. Guess we'll have to report on how we couldn't find the test.
'Insert reporting mechanism here.
End If
WScript.Quit(returnCode)
尽管如此,任务仍在继续运行,我必须在任务计划程序中手动结束任务。我不确定这是脚本本身的问题,还是UFT的问题,我对VBS的UFT不太熟悉。