TestComplete作為一個(gè)軟件自動(dòng)化測(cè)試的IDE,留有少量接口供不同的人在不同的場(chǎng)景下運(yùn)行項(xiàng)目,那么如何通過腳本去簡(jiǎn)化和更加智能的啟動(dòng)它并執(zhí)行它的項(xiàng)目呢?
成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供肇東網(wǎng)站建設(shè)、肇東做網(wǎng)站、肇東網(wǎng)站設(shè)計(jì)、肇東網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、肇東企業(yè)網(wǎng)站模板建站服務(wù),10多年肇東做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
下面是TestComplete 提供的Command line:
TestComplete.exe [file_name [/run
[(/project:project_name) |
(/project:project_name /projectitem:item_name) |
(/project:project_name /test:test_name) |
(/project:project_name /unit:unit_name /routine:routine_name)]
[/exit]] [/SilentMode [/ErrorLog:File_name]] [/ExportLog:File_name]
[Timeout:Time_in_seconds] [/ForceConversion] [/ns]
下面就根據(jù)上述的命令,寫一個(gè)類似windows的計(jì)劃任務(wù)功能的可指定執(zhí)行時(shí)間和項(xiàng)目路徑去執(zhí)行TC項(xiàng)目的腳本……
方案一:思路是用dos命令實(shí)現(xiàn),set /p命令定義一個(gè)可接收輸入值的變量,然后將改變量值與當(dāng)前時(shí)間對(duì)比,約定時(shí)間的格式,if判斷相等就執(zhí)行,否則就等待~
具體batch腳本如下:
@echo off @echo /**************** begin *************/ ::author Alan_Y set /p executeTime=Please input the execution time(format:hhmm ,such as 1930): set /p projectModel=Please input project model(1:TestItems , 2:Main): set TCexePath=E:\software\TestComplete10\TestComplete.exe if %projectModel% EQU 1 ( set projectPath="E:\Learning\AutoTest\AutoTest.mds" ) else ( set projectPath="E:\Learning\AutoTest\AutoTestSuit.pjs" ) @echo. @echo TestComplete.exe path: %TCexePath% @echo. @echo Project path: %projectPath% @echo. set /a Timer=1 set sign=: :LOOP rem get the current time set currentTime=%time:~0,2%%time:~3,2% if %Timer% EQU 1 ( @echo the current Time: %currentTime:~0,2%%sign%%currentTime:~2,2% @echo the execute Time: %executeTime:~0,2%%sign%%executeTime:~2,2% @echo. ) else ( rem wait for 60s ping -n 60 127.0.0.1>nul 2>nul @echo the current Time: %time:~0,2%%sign%%time:~3,2% @echo the execute Time: %executeTime:~0,2%%sign%%executeTime:~2,2% @echo. ) if %currentTime%==%executeTime% ( rem kill TC process taskkill /F /IM "TestComplete*" rem run TC and execute project if %projectModel% EQU 1 ( start %TCexePath% /r /e %projectPath% ) else ( start %TCexePath% %projectPath% /r /p:AutoTest /t:"Script|fMain|main" )else ( set /a Timer=%Timer%+1 goto LOOP ) @echo /***************** end **************/
運(yùn)行的效果如下:
/**************** begin *************/
Please input the execution time(format:hhmm ,such as 1930):1830
Please input the project model(1:TestItems , 2:Main):2
TestComplete.exe path: E:\software\TestComplete10\TestComplete.exe
Project path: "E:\Learning\AutoTest\AutoTest.mds"
the current Time: 15:35
the execute Time: 18:30
the current Time: 15:36
the execute Time: 18:30
the current Time: 15:37
the execute Time: 18:30
……直到執(zhí)行
補(bǔ)充~~~~~~
方案二:通過VBScript 腳本實(shí)現(xiàn)運(yùn)行項(xiàng)目(VBScript作為腳本語(yǔ)言,沒有提供GUI控制界面,但可以通過內(nèi)嵌html代碼來實(shí)現(xiàn)界面操作):
dim projectPath,executeTime,executeHour,executeMinute,currentHour,currentMinute,interval set ie=wscript.createobject("internetexplorer.application","event_") '創(chuàng)建ie對(duì)象' ie.menubar=0 '取消菜單欄' ie.addressbar=0 '取消地址欄' ie.toolbar=0 '取消工具欄' ie.statusbar=0 '取消狀態(tài)欄' ie.width=400 '寬400' ie.height=400 '高400' ie.resizable=0 '不允許用戶改變窗口大小' ie.navigate "about:blank" '打開空白頁(yè)面' ie.left=fix((ie.document.parentwindow.screen.availwidth-ie.width)/2) '水平居中' ie.top=fix((ie.document.parentwindow.screen.availheight-ie.height)/2) '垂直居中' ie.visible=1 '窗口可見' with ie.document '以下調(diào)用document.write方法,' .write "Project Scheduler " '寫一段html到ie窗口中。' .write "Project Scheduler
" .write "
" .write "" .write "Select the Project path that you need to run." .write "
Project Path:
" .write "" .write "Input the execution time(24H) that you expect to run." .write "
Expected Time:" .write "
" .write " " .write "" .write "" end with 'author Alan_Y dim wmi '顯式定義一個(gè)全局變量 set wnd=ie.document.parentwindow '設(shè)置wnd為窗口對(duì)象 set id=ie.document.all '設(shè)置id為document中全部對(duì)象的集合 id.confirm.onclick=getref("confirm") '設(shè)置點(diǎn)擊"確定"按鈕時(shí)的處理函數(shù) id.cancel.onclick=getref("cancel") '設(shè)置點(diǎn)擊"取消"按鈕時(shí)的處理函數(shù) do while true '由于ie對(duì)象支持事件,所以相應(yīng)的 wscript.sleep 200 '腳本以無(wú)限循環(huán)來等待各種事件 loop sub event_onquit 'ie退出事件處理過程' wscript.quit '當(dāng)ie退出時(shí),腳本也退出' end sub sub cancel '"取消"事件處理過程' ie.quit '調(diào)用ie的quit方法,關(guān)閉IE窗口,隨后會(huì)觸發(fā)event_onquit,于是腳本也退出了' end sub sub confirm '"確定"事件處理過程,這是關(guān)鍵' with id if .proPath.value="" then .info.value="The Project Path can not be null." exit sub else projectPath = .proPath.value set fs =WScript.CreateObject("Scripting.FileSystemObject") if fs.FileExists(projectPath) = true then if .execTime.value <> "" and InStr(.execTime.value,":")>0 then executeTime = .execTime.value executeHour = CInt(split(executeTime,":")(0)) executeMinute = CInt(split(executeTime,":")(1)) currentHour = Hour(now) currentMinute = Minute(now) if((executeHour*60 + executeMinute) < (currentHour*60 + currentMinute)) then 'another day interval = CInt((executeHour + 24 - currentHour)*60 + executeMinute - currentMinute) 'ms else interval = CInt((executeHour - currentHour)*60 + executeMinute - currentMinute) 'ms end if dim WshShell set WshShell = WScript.CreateObject("WScript.Shell") if interval>0 then .confirm.disabled="disabled" Do while interval>0 .info.value= "Need to wait " & interval & " minutes." WshShell.sendkeys "{f5}" 'refresh WScript.Sleep(60000)'sleep 60s interval = interval -1 Loop if interval=0 then dim strCommand strCommand = "start " & Chr(34) & "TestComplete.exe" & Chr(34) & " /r /e " & Chr(34) & projectPath & Chr(34) .info.value = strCommand WshShell.Run strCommand , 0 ,true end if end if else .info.value="The format of Execution Time is not correct, please input again." exit sub end if else .info.value="The Project Path is invalid, check it please." exit sub end if end if end with end sub
界面效果:
方案三:JavaScript代碼實(shí)現(xiàn)上述功能(目的很明確,就是要實(shí)現(xiàn)Confirm按鈕的onclick()事件):
Project Scheduler Project Scheduler
Select the Project path that you need to run.
Project Path:
Input the execution time(24H) that you expect to run.
Expected Time:
效果基本上跟vbs實(shí)現(xiàn)的界面效果……