如何从命令行运行QTP测试?

Ept*_*tin 4 command-line automated-tests batch-file qtp

在某些情况下,我需要从命令提示符启动并运行QTP测试.例如,我想使用Windows任务计划程序在整个晚上的不同时间运行QTP测试,但是(似乎)没有可以使用QTP.exe打开并运行测试的标志.我怎么能做到这一点?

Ept*_*tin 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
Run Code Online (Sandbox Code Playgroud)

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

  • 如果有人知道如何将QTP从"交互"模式更改为"批量"模式,那将非常感激. (2认同)
  • 是否有可能使脚本无需打开QTP/UFT gui即可静默运行测试? (2认同)