Forum Discussion

ringraham's avatar
ringraham
Contributor
9 years ago
Solved

How to continue script until polling event (via timer) determines script should stop?

I would like to have my script continue running until a given event has occurred. I have a timer event that polls every 10 seconds. When it finds that a given button has been reenabled, I would like the script to then close the application. I have tried to put a delay at the end of the main script, but this just causes TestComplete to hang. If I remove the timer event, the delay works as expected.

 

I am also open to other suggestions on how to continue a script until a given event occurs. Thanks in advance.

  • I think I got this time. Please, try this:

     

    while ( ! myRewindButton.Enabled || TimeOutNotReached )

    {

      

    }

     

    Let me know if that helps.

     

    Regards,

     

    Leandro de Araújo Souza

8 Replies


  • ringraham wrote:

    I would like to have my script continue running until a given event has occurred.


     

    Hello ringraham,

     

    You could use Runner.Stop(true), that will stop the current test running.

     

    Let me know if that helps.

    Regards,

     

    Leandro de Araújo Souza

    • ringraham's avatar
      ringraham
      Contributor

      Hi Leandro,

       

      Thanks very much for that idea. I didn't know about the Runner.Stop. However, my problem isn't stopping the script, my problem is allowing a script to keep running. I have a main script that performs a number of tests while running a certain file that is being "played back". However, there are a number of screen image compares I want to do once the file has completed playing. I have a timer going off every 10 seconds that checks to see when the "Rewind" button has been re-enabled, thus indicating the file is done playing. This is setup from the main test script. Unfortunately, the main test script stops everything once it reaches the bottom of the script. I'm looking for a way to continue the test until the "rewind" button is re-enabled, screen compare tests are done, and then I can call the Runner.Stop command.

       

      Hope this makes more sense. Thanks again.

       

      -Ron

  • Curiosity, I use the following idea, when I use a function that expects certain object:

     

    Project.Variables.DelayDefault  : = Options.Run.Timeout;

     

    Options.Run.Timeout : =  0;

     

    //user function to wait for the object

    Options.Run.Timeout : =  Project.variables.DelayDefault;

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      You may also consider the .WaitProperty() method (http://support.smartbear.com/viewarticle/55099/) to eliminate the custom loop. Something like this (untested pseudo-code):

      If (Not button.WaitProperty("Enabled", True, Options.Run.Timeout)) Then

        Call Log.Warning(aqString.Format("Button did not become enabled within %i seconds", Options.Run.Timeout / 1000))

      End If

      Call button.click

      ...