Dim qtApp Dim qtTest Dim qtResultsOpt Dim GenerateDateTime,TestResult,BakTestResult GenerateDateTime =Replace(FormatDateTime(Date(),2),"/","_") & "-" & Replace(FormatDateTime(Time(),3),":","_") '自定义一个获取当前时间的字符串 TestResult = "C:\AutoTest\TA_AutomationTest\1_Report\ExcelReport\Test_Result.xls" '获得测试结果 BakTestResult = "C:\AutoTest\TA_AutomationTest\1_Report\ExcelReport\Test_Result" & GenerateDateTime & ".xls" Set qtApp = CreateObject("QuickTest.Application") ' 建立QTP的应用对象 qtApp.Launch ' Start QuickTest qtApp.Visible = True ' 让QTP运行过程可见 ' 设置当运行过程中如果出错,抓图。 qtApp.Options.Run.ImageCaptureForTestResults = "OnError" ' 快速运行。 qtApp.Options.Run.RunMode = "Fast" qtApp.Options.Run.ViewResults = False qtApp.Open "C:\AutoTest\TA_AutomationTest\C955\3_QTPScript\0_MainScript\MainScript2", True ' 以只读的方式开打开QTP主函数 ' 为Test设置运行 Set qtTest = qtApp.Test Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' 建立测试结果 qtResultsOpt.ResultsLocation = "C:\AutoTest\TA_AutomationTest\1_Report\" & GenerateDateTime ' 建立起QTP自动的测试结果路径 'qtResultsOpt.ResultsLocation = "D:\temp2\res1" qtTest.Run qtResultsOpt ' 运行QTP主函数 qtTest.Close ' 关闭主函数 qtApp.Quit ' 退出 Set qtResultsOpt = Nothing ' 释放对象 Set qtTest = Nothing Set qtApp = Nothing Set fso = CreateObject("Scripting.FileSystemObject") fso.MoveFile TestResult, BakTestResult '备份当前运行完脚本后的测试结果 Set fso = Nothing |