Forum Discussion

gnms's avatar
gnms
Occasional Contributor
14 years ago

Clean up after Log.Error

Hi

When running a test and get an error (Log.Error)  the test stops and do not clean up the stuff that must be cleaned up after each test.  


Unit test framework have setup and teardown methods that always runs before and after each test, is it possibly to achieve that in TestComplete?


If not, how can I solve the clean up after Log.Error?

 


Thanks

Mats

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    TestComplete has the ability to add event handlers "OnLogError" and "OnStopTest".  Take a look at the help topics for those two items and see if that helps.
  • gnms's avatar
    gnms
    Occasional Contributor

    OK, but those events is called each time an error occurs, I will be able to do different action on different tests. Some test is testing interface to other systems and then I need to start a simulator and then stop it when test I finished. If the test fails I will still shut down the simulator.


    Is it possibly to detect which test that has raised the event?


    I have not been able to find any documentation on what properties the event has that is sent to OnLogError.


    Thanks

    Mats

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Two suggestions:



    1)  Build into your tests some sort of identifying or classification factor that is "standardized" and is stored in some sort of global location (like Project.Variables).  Then, in your OnLogError event handler, check that global location and perform a script based upon what is found there.  This could be the type of error encountered (easy to do with try/catch/finally code in JScript and DelphiScript), or the type of test being performed, or some other thing.  Takes some code work, but it can be done.



    2)  Determine a universal starting point for all tests.  Then, when an error occurs, clear out the system and set it up again back to the universal starting point so that your next test will be able to execute accordingly.
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Mats,


    If you run tests as test items, then you can determine the current test item's name by using the Project.TestItems.Current.Name property.


    If you start tests by running a script routine or keyword test, then, unfortunately, there is no way to determine the current test name. A workaround, as Robert wrote, is to use some global storage like Project.Variables or script's global variable that will keep the current test name. Most likely, the number of tests that require unique actions on error is not large. So, you will be able to add code (or keyword test operations) that will save the test name to this variable at the beginning of the test and clear the variable on exit. If you use JScript, you can use the Array object (JScript object) to implement a kind of a stack and use this object's push and pop methods to save and restore test' names.