Showing results for 
Search instead for 
Did you mean: 

OnStopTest & Sys.Shutdown on last Test Item


OnStopTest & Sys.Shutdown on last Test Item


i need some help with scripting. i want that my local computer is shutting down when the last project item is finished. i got this so far (i have to name the last test in project items list - not really what i want - it differs which one is last).

procedure shutdown_OnStopTest(Sender);
  if (Project.TestItems.Current.Name = 'last_test') then


viva la software ergonomica!
Community Hero

Re: OnStopTest & Sys.Shutdown on last Test Item

OnStopTest is usually will come to picture once after all test items or scripts or whatever Test Complete executing  are completed.


As per my point, You don't need to give any kind of if condition in the event handler.

Shankar R

LinkedIn | CG-VAK Software | Bitbucket |

“You must expect great things from you, before you can do them”

Extension Available

Community Hero

Re: OnStopTest & Sys.Shutdown on last Test Item

Actually, the onstoptest will fire upon the ending of any item listed as a "Test Item" in the project test items panel.


I think that you can check to see what the index of the current test item is, check that against the total number of test items, and from there determine if it's the last one.

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Regular Contributor

Re: OnStopTest & Sys.Shutdown on last Test Item

shutting down the machine (= killing the context) from within an Event procedure may lead to unexpected results.


I'd feel better with this:

- Trigger an external script which shuts down the machine asynchronously after some delay (10 min?).

This will give TC the Chance to end the test run as planned, write the logs and so on, without being forced to shut down by the OS

Community Hero

Re: OnStopTest & Sys.Shutdown on last Test Item



I would be second to Manfred.


Additionally: In general, it is near to impossible in TestComplete to figure-out from test code if the given test item is the last one that is going to be executed or not. Thus, it is more safe and reliable to shut down the box via some external action triggered when the test run is over.

  /Alex [Community Hero]
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.

Re: OnStopTest & Sys.Shutdown on last Test Item

ok i see,

the code i posted above is for hardcoded testname only. it works fine so far.


but if i want a system shutdown after the last test item in list finished, i will use the way tristaanogre described:

  1. get test.items & check if enabled
  2. if enabled: count them
  3. get name from last enabled one & compare to current
  4. if last enabled = current then sys.shutdown

when i´m done i will posting the code here. maybe someone will need it in the future again 🙂

viva la software ergonomica!
New Here?
Join us and watch the welcome video:
Top Kudoed Authors