cancel
Showing results for 
Search instead for 
Did you mean: 

OnStopTestCase event handler going in Loop

pankhuri
Occasional Contributor

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 4
ebarbera
Staff

Re: OnStopTestCase event handler going in Loop

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
Occasional Contributor

Re: OnStopTestCase event handler going in Loop

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
Community Hero

Re: OnStopTestCase event handler going in Loop

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;

}

 

Regards,
  /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.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
pankhuri
Occasional Contributor

Re: OnStopTestCase event handler going in Loop

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

New Here?
Join us and watch the welcome video:
Announcements