Forum Discussion

Al2's avatar
Al2
Occasional Contributor
6 years ago
Solved

Using 'Timer' for Modal Overlays

Hi,

 

I have a question related to the use of Timer.

I don't understand what unit_name refers to here? 

 

I was running a program without using any unit reference and it errored. Any help would be appreciated!

 

 

Thank you

Al

7 Replies

  • unit name = code unit.

    In the screenshot below, the items in the red box are units.  Within those units, you write functions, methods, routines, etc.  So, for your question, if I have a routine that I want to run on a timer called 'fightMe' and that routine is in the unit 'BridgeOfKhazadum', then the syntax of that Timer would be to use 

     

    var MyTimer = Utils.Timers.Add(10000, 'BridgeOfKhazadum.fightMe', true);

     

    • Al2's avatar
      Al2
      Occasional Contributor

      Thank you tristaanogre  I was thinking the same and then I exported funtion, and there was an error. so it confused me. I should not export and just use it with filename reference.

       

      So, I'm using this callTimerRoutines function to call the 'timeRoutine' function.

      When the 'timeRoutine' is called and the object in the if statement doesn't exist, it should just move on without waiting to find that object, but it's not the case.

       

      What I see is  this. Why would it wait for this object if the object doesn't exist?

       

       

      function callTimerRoutines(){ 
          var MyTimer = Utils.Timers.Add(10000, "Startup.timeRoutine", true);
      }
      
      //StartUp unit
      
      function timeRoutine(){ 
      if(!Aliases.panelErrorpanel.Exists){
      Log.Message("Move");
      }else{ 
      Log.Error(Aliases.panelErrorpanel.panelErrorContent.panelErrorContainer.textContent);
      Log.Picture(Sys.Desktop, "Modal Dialog", ) 
      Aliases.panelErrorpanel.panelErrorContent.panelErrorContainer.buttonOk.ClickButton();
      }
      }

      Appreciate your help!

       

      Thank you

      Al

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        If you understand objects, then you understand properties of objects.  Exists is a property of the object Aliases.panelErrorpanel.  In order to check the Exists property, it first needs to detect if the object exists.  Well, if the object does not exist, it can't check the Exists property so, most likely, you'll get an error in your log saying something like "Aliases.panelErrorpanel does not exist"... which you're like... "Well, DUH!!!"

         

        So... to check existance of an object as you want to, rather than just checking the Exists property, you need to first Wait to see if the object comes around.  If it does , THEN you can start looking at properties.

         

        So...  Just some light reading...https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html

        From that, I'd change your code to the following (see below).  Note the use of WaitAliasChild.  I have the timer set to 20 seconds on that method.  That means, it will wait up to 20 seconds for the object to return.  If it does, the object itself is returned and "Exists" is true.  If it doesn't, then a "stub" object with no properties but the "Exists" property is returned and that has a value of "false".

         

        function callTimerRoutines(){ 
            var MyTimer = Utils.Timers.Add(10000, "Startup.timeRoutine", true);
        }
        
        //StartUp unit
        
        function timeRoutine(){ 
        if(!Aliases.WaitAliasChild('panelErrorpanel', 20000).Exists){
        Log.Message("Move");
        }else{ 
        Log.Error(Aliases.panelErrorpanel.panelErrorContent.panelErrorContainer.textContent);
        Log.Picture(Sys.Desktop, "Modal Dialog", ) 
        Aliases.panelErrorpanel.panelErrorContent.panelErrorContainer.buttonOk.ClickButton();
        }
        }