Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A custom script runs the TestComplete project

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

TestComplete, as an IDE for software automation testing, leaves a small number of interfaces for different people to run projects in different scenarios, so how to simplify and more intelligently start it and execute its projects through scripts?

Here is the Command line provided by TestComplete:

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]

According to the above command, write a script similar to windows's scheduled task function that can specify the execution time and project path to execute the TC project.

Plan 1: the idea is to use the dos command to implement. The set / p command defines a variable that can receive the input value, then compares the changed value with the current time, agrees on the format of the time, and executes the if judgment, otherwise it will wait.

The specific batch script is as follows:

@ echo off@echo / * begin * /: author Alan_Yset / 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.exeif% 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=1set sign=::LOOPrem get the current timeset currentTime=%time:~0,2%%time:~3,2%if% Timer% EQU 1 (@ echo the currentTime: % currentTime:~0,2%%sign%%currentTime:~2,2% @ echo the executeTime:% 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 currentTime:% time:~0,2%%sign%%time:~3,2% @ echo the executeTime:% 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 * /

The effect of running is as follows:

/ * 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

…… Until the execution

Supplement ~

Solution 2: run the project through VBScript script (VBScript as a scripting language, does not provide GUI control interface, but you can implement interface operation by embedding html code):

Dim projectPath,executeTime,executeHour,executeMinute,currentHour,currentMinute,intervalset ie=wscript.createobject ("internetexplorer.application" "event_") 'create ie object' ie.menubar=0 'cancel menu bar' ie.addressbar=0 'cancel address bar' ie.toolbar=0 'cancel toolbar' ie.statusbar=0 'cancel status bar' ie.width=400 'wide 400'ie.height=400' high 400'ie.resizable=0'do not allow users to change window size 'ie.navigate "about:blank"' open blank page 'ie.left=fix ((ie.document.parentwindow.screen.availwidth-ie.width) / 2) 'horizontal Center' ie.top=fix ((ie.document.parentwindow.screen.availheight-ie.height) / 2) 'Vertical Center' window can be seen below 'with ie.document' to call the [xss_clean] method '.write "Project Scheduler"' write a html to the ie window.' .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_Ydim wmi 'explicitly define a global variable set wnd=ie.document.parentwindow' set wnd as window object set id=ie.document.all 'set id to the collection of all objects in document id.confirm.onclick=getref ("confirm")' set the handler id.cancel.onclick=getref ("cancel") 'setting when the "OK" button is clicked The handler function do while true 'when canceling the button because the ie object supports events So the corresponding wscript.sleep 200' script waits for various events loopsub event_onquit'ie exit event handler 'wscript.quit' when ie exits, the script also exits' end subsub cancel'"cancel" event handler 'ie.quit' to call ie's quit method, closes the IE window, and then triggers event_onquit, so the script also exits the 'end subsub confirm' "OK" event handler. This is the key '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. Interval = "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 withend sub

Interface effect:

Scenario 3: the JavaScript code implements the above functions (the purpose is clear, that is, to implement the onclick () event of the Confirm button):

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:

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.";}}

The effect is basically the same as the interface effect achieved by vbs.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report