Originally posted by mfoster711 on November 04, 2025
In my code, I want to check for a certain condition and if it is true then stop execution of the script and close TestComplete. How can this be done?
I know that the /exit option is available if I started the script from command line. But, I was looking for an option that would work when manually running scripts or running from command line.
I am also aware of aqEnvironment.RebootAndContinue but I don’t need to reboot. I just want to exit TestComplete.
Originally posted by scot1967 on November 04, 2025
Stopping the script is easy but closing TC requires a bit more thought. Have you tried calling a PowerShell script in code your code, say from an error handler like try/catch or from an event?
Originally posted by scot1967 on November 04, 2025
I forgot about the .close and .terminate methods. If you can snag the TC process you may be able to use one of these methods. The terminate method is the more risky of the two but may be the only way. It just kills the process instead of asking politely to close properly.
Originally posted by scot1967 on November 04, 2025
ps… you can stop the script by logging an error (if your project setting are set to “Stop on Error”) or you can do a runner.stop or a runner.halt to stop the test. I would add this to a try catch using a throw to issue an error and hit the catch bypassing the rest of the script.
Originally posted by rraghvani on November 05, 2025
Use Runner Object Methods, together with your /exit command-line paremeter. For example,
function loop()
{
for (var i = 0; i < 100; i++) {
if (i = 50) {
Log.Message(`Stopping loop at ${i}`);
Runner.Stop();
}
}
Log.Message("This line is not called!");
}
Originally posted by Hassan_Ballan on November 05, 2025
Great thread — lots of solid tips already!
Just to sum it up for anyone checking this out later: you can stop a test run with Runner.Stop() or Runner.Halt(), optionally close TestComplete (or TestExecute) using Sys.Process(“TestComplete”).Terminate() — or call a PowerShell script if you want a cleaner shutdown.
Here’s a quick example in JavaScript:
function checkConditionAndExit() {
if (Project.Variables.MyFlag == true) {
Log.Message("Condition met — stopping and closing TestComplete...");
Runner.Stop(true); // stop execution
}
}
I’d still be careful with Terminate() — it’s basically the “pull the plug” option and can skip saving logs or logging out from license. If you’re running from the command line, the /exit flag is still the smoothest way to finish up.
AI-assisted response Found it helpful? Click Like Issue resolved? Click Mark as Solution
Originally posted by rraghvani on November 05, 2025
I have no idea why your ChatGPT has suggested to terminate the process of TestComplete, and then suggesting to be careful!? If you are running automation, don’t terminate the TC process! Also, the remaining lines after Runner.Stop(true) will not get called!
Originally posted by Hassan_Ballan on November 05, 2025
You’re right — suggesting Sys.Process(“TestComplete”).Terminate() was a mistake. That’s unsafe and any code after Runner.Stop(true) won’t run.
The correct way is just to use Runner.Stop() or Runner.Halt(), and use the /exit flag from the command line if you want TestComplete/TestExecute to close automatically.
Originally posted by mfoster711 on November 05, 2025
I ended up going with the option to user a PowerShell script. My normal script will run the PowerShell script and stop. This leaves TestComplete open but stopped. The PowerShell script pauses for 20 seconds (to ensure TestComplete has stopped) and then forces TestComplete to close. Not the most elegant, but it works.
Originally posted by rraghvani on November 06, 2025
Have you tried with /exit command-line parameter, as opposed to terminating the process? Terminating the process, may not release the license and when you relaunch TC, it will say that the license is in use.
Originally posted by scot1967 on November 06, 2025
rraghvani Could /exit work? It looks unlikely unless TC is started with the /run option given the docs. Have you had success?
/exit (or /e)
If this argument is used along with the /run argument, TestComplete will close after the project (or project suite) run is over. If the /exit command-line argument is used without /run, then neither the specified project (project) suite will be run, nor will TestComplete be closed.
Note:
If you run tests, the project (or project suite) file will be changed because it will contain a reference to the new log file. TestComplete will display the Confirm dialog asking you to save the changes. To suppress displaying the dialog on exit, specify the /SilentMode command-line argument along with /exit.
Originally posted by rraghvani on November 06, 2025
Using /exit together with the appropriate parameters, works. To run TC scripts from the command prompt, you have to include /run, /project and/or /unit, /routine followed by /exit.
Originally posted by scot1967 on November 06, 2025
Given this clip from the original post I think this isn’t what is desired. But yes, I agree. It would work if started from the command line.
I know that the /exit option is available if I started the script from command line. But, I was looking for an option that would work when manually running scripts or running from command line.
Originally posted by scot1967 on November 06, 2025
I added my concern about terminating TC in one of the first post here. These would be my biggest concerns. I am not sure if the log file is being lost in the project or not, or if a licensing issue will be seen these are valid points to consider as well as the corruption the project file. I am sure this user has considered the risk.
Originally posted by scot1967 on November 06, 2025
…
I forgot about the .close and .terminate methods. If you can snag the TC process you may be able to use one of these methods. The terminate method is the more risky of the two but may be the only way. It just kills the process instead of asking politely to close properly.
Originally posted by rraghvani on November 06, 2025
You have to gracefully exit the application, and the only way of doing that, is by using the command line parameters. Any other alternative suggestions such as killing the process is not recommended.
It’s like suggesting to pull the mains plug out to turn the computer off, it shouldn’t be recommended!
Originally posted by scot1967 on November 06, 2025
Apologies, my last two posts are at the wrong nested level and were replies to rraghvani. I think this leveled nesting of comments is confusing. I like a flat structure using mentions with @…
Originally posted by scot1967 on November 06, 2025
Let me get these posts in the right place…
I added my concern about terminating TC in one of the first post here. These would be my biggest concerns. I am not sure if the log file is being lost in the project or not, or if a licensing issue will be seen these are valid points to consider as well as the corruption the project file. I am sure this user has considered the risk.
…
I forgot about the .close and .terminate methods. If you can snag the TC process you may be able to use one of these methods. The terminate method is the more risky of the two but may be the only way. It just kills the process instead of asking politely to close properly.