2012-12-17 36 views
4

有幾種情況需要從命令提示符啓動並運行QTP測試。例如,我想使用Windows任務計劃程序在整個晚上的不同時間運行QTP測試,但是(看起來)沒有我可以使用的標誌打開QTP.exe並運行測試。我怎樣才能做到這一點?如何從命令行運行QTP測試?

回答

8

這是真的,用的QuickTest Pro,您不能直接通過調用C:\Program Files (x86)\HP\QuickTest Professional\bin\QTPro.exe "C:\Some Test\"
所有的希望都不會丟失運行測試,但是。有一種方法可以創建一個小VBS文件,該文件可以在調用VBS文件時運行任意QTP測試。 這比爲每個測試創建一個批處理文件要好得多。

'******************************************************************* 
'RunThisTest 
'by Michael Innes 
'November 2012 

testResourcePath = "C:\Test Logs and Results\" 

'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 qtApp 'Declare the Application object variable 
    Dim qtTest '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 
    qtApp.Open testPath, False 'Open the test in read-only mode 
    Set qtTest = qtApp.Test 

    'Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object 
    'qtResultsOpt.ResultsLocation = testResourcePath ' Specify the location to save the test results. 
    'qtTest.Run qtResultsOpt,True 'Run the test and wait until end of the test run 

    qtTest.Run 'Run the test 
    qtTest.Close 'Close the test 
    qtApp.Quit 
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 

要使用上面的代碼,執行下面的命令:cscript.exe "C:\RunThisTest.vbs" "L:\Test Path\The Test Itself\"

+2

如果有人知道如何將QTP從'交互'模式更改爲'批'模式,那將非常感激。 – Eptin

+2

是否可以讓腳本靜靜地運行測試,而無需打開QTP/UFT GUI? – 2013-10-23 10:55:53

2

的多線程驅動工具可以執行腳本爲您服務。

> mdrv.exe -usr "c:\test\foo.usr" 
相關問題