讓你的自動(dòng)化測(cè)試更加“自動(dòng)化”
前段時(shí)間,老板要求每天包括晚上要在不同的壓力下,且不斷重復(fù)地運(yùn)行smoke test.但是晚上我們不可能就自己動(dòng)手讓我們的QTP的運(yùn)行,而且就算是白天也不可能做到在某一個(gè)時(shí)間點(diǎn)上,自己手動(dòng)來(lái)運(yùn)行自動(dòng)化測(cè)試。
那該怎么辦呢?可以考慮用Window自帶的Schedule來(lái)定時(shí)觸發(fā)我們的QTP。但是schedule是無(wú)法直接去打開(kāi)QTP或者去運(yùn)行VBS,那又該怎么辦?我是用下的解決方法與大家共享:
Schedule -> Bat -> VBS -> QTP主函數(shù) -> VBScripts.具體代碼如下:
Bat:
------------------------------------
taskkill /im EXCEL.EXE /f taskkill /im wscript.exe /f taskkill /im QTPro.exe /f taskkill /im QTAutomationAgent.exe /f ping -n 3 127.1>nul start C:\AutoTest\TA_AutomationTest\C955\3_QTPScript\0_MainScript\LaunchLoopTest.vbs **************************************************************************** |
LaunchLoopTest.vbs:
----------------------
Dim qtApp Dim qtTest Dim qtResultsOpt Dim GenerateDateTime,TestResult,BakTestResult GenerateDateTime =Replace(FormatDateTime(Date(),2),"/","_") & "-" & Replace(FormatDateTime(Time(),3),":","_") '自定義一個(gè)獲取當(dāng)前時(shí)間的字符串 TestResult = "C:\AutoTest\TA_AutomationTest\1_Report\ExcelReport\Test_Result.xls" '獲得測(cè)試結(jié)果 BakTestResult = "C:\AutoTest\TA_AutomationTest\1_Report\ExcelReport\Test_Result" & GenerateDateTime & ".xls" Set qtApp = CreateObject("QuickTest.Application") ' 建立QTP的應(yīng)用對(duì)象 qtApp.Launch ' Start QuickTest qtApp.Visible = True ' 讓QTP運(yùn)行過(guò)程可見(jiàn) ' 設(shè)置當(dāng)運(yùn)行過(guò)程中如果出錯(cuò),抓圖。 qtApp.Options.Run.ImageCaptureForTestResults = "OnError" ' 快速運(yùn)行。 qtApp.Options.Run.RunMode = "Fast" qtApp.Options.Run.ViewResults = False qtApp.Open "C:\AutoTest\TA_AutomationTest\C955\3_QTPScript\0_MainScript\MainScript2", True ' 以只讀的方式開(kāi)打開(kāi)QTP主函數(shù) ' 為Test設(shè)置運(yùn)行 Set qtTest = qtApp.Test Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' 建立測(cè)試結(jié)果 qtResultsOpt.ResultsLocation = "C:\AutoTest\TA_AutomationTest\1_Report\" & GenerateDateTime ' 建立起QTP自動(dòng)的測(cè)試結(jié)果路徑 'qtResultsOpt.ResultsLocation = "D:\temp2\res1" qtTest.Run qtResultsOpt ' 運(yùn)行QTP主函數(shù) qtTest.Close ' 關(guān)閉主函數(shù) qtApp.Quit ' 退出 Set qtResultsOpt = Nothing ' 釋放對(duì)象 Set qtTest = Nothing Set qtApp = Nothing Set fso = CreateObject("Scripting.FileSystemObject") fso.MoveFile TestResult, BakTestResult '備份當(dāng)前運(yùn)行完腳本后的測(cè)試結(jié)果 Set fso = Nothing |
posted on 2014-01-09 10:42 順其自然EVO 閱讀(278) 評(píng)論(0) 編輯 收藏 所屬分類: qtp