TestComplete作為一個軟件自動化測試的IDE,留有少量接口供不同的人在不同的場景下運行項目,那么如何通過腳本去簡化和更加智能的啟動它并執(zhí)行它的項目呢?
成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供肇東網(wǎng)站建設(shè)、肇東做網(wǎng)站、肇東網(wǎng)站設(shè)計、肇東網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、肇東企業(yè)網(wǎng)站模板建站服務(wù),10多年肇東做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(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ù)上述的命令,寫一個類似windows的計劃任務(wù)功能的可指定執(zhí)行時間和項目路徑去執(zhí)行TC項目的腳本……
方案一:思路是用dos命令實現(xiàn),set /p命令定義一個可接收輸入值的變量,然后將改變量值與當前時間對比,約定時間的格式,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 **************/
運行的效果如下:
/**************** 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í)行
補充~~~~~~
方案二:通過VBScript 腳本實現(xiàn)運行項目(VBScript作為腳本語言,沒有提供GUI控制界面,但可以通過內(nèi)嵌html代碼來實現(xiàn)界面操作):
dim projectPath,executeTime,executeHour,executeMinute,currentHour,currentMinute,interval set ie=wscript.createobject("internetexplorer.application","event_") '創(chuàng)建ie對象' 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" '打開空白頁面' 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 "<html><title>Project Scheduler</title><body bgcolor=#ffffff scroll=no>" '寫一段html到ie窗口中。' .write "<h3 align=center>Project Scheduler</h3>" .write "<input id=info type=text color=red size=400 style='color:red;background:white;border:1px;border-bottom-style:none;border-top-style:none;border-left-style:none;border-right-style:none;'><br>" .write "<p align=left>" .write "<font color=blue size=2>Select the Project path that you need to run.</font>" .write "<p>Project Path:<input id=proPath type=file size=19><br>" .write "<p align=left>" .write "<font color=blue size=2>Input the execution time(24H) that you expect to run.</font>" .write "<p>Expected Time:<input id=execTime type=text size=30 onfocus='this.select();'value='19:30'>" .write "<p align=center><br><br>" .write "<input id=confirm type=button value='Confirm'> " .write "<input id=cancel type=button value='Cancel'>" .write "</body></html>" end with 'author Alan_Y dim wmi '顯式定義一個全局變量 set wnd=ie.document.parentwindow '設(shè)置wnd為窗口對象 set id=ie.document.all '設(shè)置id為document中全部對象的集合 id.confirm.onclick=getref("confirm") '設(shè)置點擊"確定"按鈕時的處理函數(shù) id.cancel.onclick=getref("cancel") '設(shè)置點擊"取消"按鈕時的處理函數(shù) do while true '由于ie對象支持事件,所以相應(yīng)的 wscript.sleep 200 '腳本以無限循環(huán)來等待各種事件 loop sub event_onquit 'ie退出事件處理過程' wscript.quit '當ie退出時,腳本也退出' end sub sub cancel '"取消"事件處理過程' ie.quit '調(diào)用ie的quit方法,關(guān)閉IE窗口,隨后會觸發(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代碼實現(xiàn)上述功能(目的很明確,就是要實現(xiàn)Confirm按鈕的onclick()事件):
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Project Scheduler</title> </head> <body> <h2>Project Scheduler</h2> <hr> <input id=info type=text color=red size=400 style='color:red;background:none;border:1px;border-bottom-style:none;border-top-style:none;border-left-style:none;border-right-style:none;'><br> <p align=left> <font color=blue size=4>Select the Project path that you need to run.</font> <p>Project Path:<input id=proPath type=file size=19><br> <p align=left> <font color=blue size=4>Input the execution time(24H) that you expect to run.</font> <p>Expected Time:<input id=execTime type=text size=30 onfocus='this.select();'value='such as: 19:30'> <br><br> <input id="confirm" type="button" value="Confirm"> <input id="cancel" type="button" value="Cancel"> <script language="javascript"> var btnCancel = document.getElementById("cancel"); btnCancel.onclick = function(){ window.opener=null; window.close(); } //author Alan_Y var btnConfirm = document.getElementById("confirm"); var txtInfo = document.getElementById('info'); btnConfirm.onclick = function(){ var path = document.getElementById('proPath'); if(path.value !=""){ path.select(); var projectPath = document.selection.createRange().text; var fs = new ActiveXObject("Scripting.FileSystemObject"); if(fs.FileExists(projectPath)){ var txtTime = document.getElementById('execTime'); if (txtTime.value != ""&& (txtTime.value).indexOf(":")!=-1) { var executeTime = txtTime.value; var executeHour = executeTime.split(":")[0]; var executeMinute = executeTime.split(":")[1]; var date = new Date(); var currentHour = date.getHours(); var currentMinute = date.getMinutes(); var interval = 0; if((executeHour*60 + executeMinute) < (currentHour*60 + currentMinute)){ //another day; interval = (executeHour + 24 - currentHour)*60 + executeMinute - currentMinute; //m }else{ interval = (executeHour - currentHour)*60 + executeMinute - currentMinute ;//m } var WshShell = new ActiveXObject("WScript.Shell"); if(interval>0){ btnConfirm.disabled = true; while(interval > 0){ txtInfo.value= "Need to wait " + interval + " minutes."; WshShell.sendkeys("{f5}"); //refresh WScript.Sleep(60000); //sleep 60s interval--; } } if(interval==0){ var strCommand = "start "+ "TestComplete.exe" + " /r /e \"" + projectPath + "\""; txtInfo.value = strCommand; alert(strCommand); WshShell.Run(strCommand,true); } }else{ txtInfo.value = "The format of Execution Time is not correct, please input again."; } }else{ txtInfo.value = "The Project Path is invalid, check it please."; } }else{ txtInfo.value = "The Project Path can not be null."; } } </script> </body> </html>
效果基本上跟vbs實現(xiàn)的界面效果……
網(wǎng)站名稱:自定義腳本運行TestComplete項目
文章網(wǎng)址:http://jinyejixie.com/article12/jjjjgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、網(wǎng)站內(nèi)鏈、網(wǎng)站策劃、服務(wù)器托管、搜索引擎優(yōu)化、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)