Forum Discussion

CBleunven's avatar
CBleunven
Contributor
9 years ago

GeneralEvents_OnStopTest(Sender) - differentiate manual stop from others

Hi,

In order to perform some actions when ending a test, I use the classic function GeneralEvents_OnStopTest(Sender) linked to the OnStopTest event.

I would like to have a different behavior when I manually stop a test (using the STOP button) than when a test closes for another reason. More particularly when a test ended, I check for remaining processes and kill them if exist, that's I would like to avoid when stopping test manually.

I didn't find a way to discriminate between the two situations.

First I was looking to check some properties of the Sender object but this one is always "undefined".

In another hand, as an error labelled "Script execution was interrupted." is added to the Log when a test is manually stopped, I've also tried to check for the "Script execution was interrupted." message in the GeneralEvents_OnLogError(Sender, LogParams) method, but this method is not called when the test is manually stopped.

 

Is there a reason why Sender is always undefined ?

Is there a way to find when test is stopped manually ?

 

Thanks for your help,

Best,

Christophe

 

I use TC 9.0.1069.7 (and can't upgrade for compatibility reason) and script are in C#Script.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    As I understand it, the "Sender" is an object that is used internally by TestComplete and is not something that can be manipulated by the script code.

    However, here's a suggestion. Since you are going to by stopping the test manually, the assumption is that you are monitoring it and are watching it manually.  So... put a breakpoint in your OnStopTest handler code before the "cleanup" and, when you hit that breakpoint, just click the "stop" button in the IDE to stop all execution. 

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor

    So I thought you could maybe evaluate the message in the log...and you can get to that by:

     

    Project.Logs.LogItem(Project.Logs.LogItemsCount - 1)

    And then by digging deep into the log like...

     

     

    Project.Logs.LogItem(Project.Logs.LogItemsCount - 1).Child(0).Child(0).Data(0).Rows(0).ChildRow(0).ChildRow(0).ValueByName("Message");

     

     

    Spoiler
    Or by using a recursive function to iterate all of the child objects of the log and grab the last message...

     

     

    BUT the problem is the log message "Script execution was interrupted." is not written until after the OnStopTest event fires.

    So I think it's probably easier to figure out where your script stops "Naturally"...

     

    Spoiler
    either it's stopping by finishing scripts, or on error

     

    and then have it call a different function to terminate the processes instead of terminating them from the OnStopTest event.