How to do test specific on stop event (clean up)?
Hi, it seems like Testcomplete (TC) has its own event handling when a Stop event occurs so the 'finally' on this test does not run. But TCs event handling is a global one (I think). How can I do a test specific cleanup on a Stop event?
Log.Message("Do cleanup for test1")
Log.Message("Do cleanup for test2")
Solved! Go to Solution.
You're using a Log.Error() to cause a Stop. If your project's Playback option "Stop on error" was not set, then you would return from the error to do the cleanup. No Stop event would occur.
If you changed your example to do a Stop directly, then there's not much more you can do after a Stop event. You won't be returning from the Stop event handler.
You could load data into a Project variable and then do something based on that:
Log.Message("cleanup for test2")
def test2(): try: Project.Variables.cleanup = 1 Runner.Stop() finally: Log.Message("will never get here") def GeneralEvents_OnStopTest(Sender): if Project.Variables.cleanup == 1: foo() Log.Message("OnStopTest done")
but don't be surprised if you can't do much more than this.