Forum Discussion

pankhuri's avatar
pankhuri
Occasional Contributor
3 years ago

OnStopTestCase event handler going in Loop

Hi, 

 

I have created an OnStopTestCase event handler for my test and in there i am reverting back the data which was done during test execution.

Now, when my test fails, it goes to OnStopTestCase event handler and tries to revert the data. But somehow, the revert fails, so it goes again to OnStopTestCase event handler. and the cycle continues.

 

Can someone help me how to break this infinite loop for the event handler?

 

Thanks in advance!

Pankhuri

 

4 Replies

  • Hi pankhuri - 

     

    I would suggest running the revert script as the last test case in your workflow. I don't believe this has to be handled as part of an event handler.

    • pankhuri's avatar
      pankhuri
      Occasional Contributor

      Hi ebarbera,

       

      Thank you for replying.

      I was doing same thing earlier what you suggested. But that piece of code or line will only get executed when test is passed successfully.

      If in between (before that revert code), the test fails, the system will be not in proper state as the changes i did while test execution, it would still be there. Because of this reason, i was trying to use OnStopTestCase event handler, so that i could revert the changes irrespective of test passed or failed.

       

      Let me know if there is any alternative way to do this. I have used Selenium before and in that we have option to  do teardown. I was hoping similar kind of thing would be present in TestComplete.

       

      Thanks,

      Pankhuri

       

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Pankhuri,

     

    Sample code that utilizes script global or Project variable:

     

    function OnStartTestCase ()

    {

      Project.Variables.InOnStopTestCaseHandler = false;

    }

     

    function OnStopTestCase()

    {

      if (Project.Variables.InOnStopTestCaseHandler)

        exit;

     

      Project.Variables.InOnStopTestCaseHandler = true;

      ...

      // do whatever you need here

      ...

      Project.Variables.InOnStopTestCaseHandler = false;

    }

     

    • pankhuri's avatar
      pankhuri
      Occasional Contributor

      Hi Alex,

       

      Thank you for providing a sample code. The logic makes sense, however when i was using Exit procedure, it is not working. It is giving error as not defined in python. Does it not work with python language?

       

      Also, how to call this exit, i am just using Exit() to call this procedure. Let me know if this is not the right way.

       

      Thanks,

      Pankhuri