Forum Discussion

Al2's avatar
Al2
Occasional Contributor
6 years ago

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 w...
  • tristaanogre's avatar
    tristaanogre
    6 years ago

    As an example.... let's consider the following basic OOP code


    class myObject{
        constructor(){
            this.Exists = true;
            this.someText = 'I think therefore I am';
        }
    }
    
    function testObject(){
        
        if (!someObject.Exists){
            Log.Message('It does not think therefore it is not')
        }
        someObject = new myObject();
        if (someObject.Exists){
            Log.Message(someObject.someText);
        }
    }

    Obviously, this is bad code. I'm trying to use the "Exists" property of someObject before the object is instantiated.  In doing so, I actually get an error in my log telling me, in no uncertain terms "Um, you did a dumb...someObject doesn't exist so I have no idea what you want me to do".

     

    What TestComplete does is that, once it finds an object and identfies it, it puts a wrapper around it based upon the kind of object it is that contains properties like "Exists" and "Visible" and so forth and contains methods like WaitChild and WaitWindow and so on.  

    So, in your case, you actually start with on object, Aliases.  That's a built in, root core object of the tool itself.  It has the WaitAliasChild method built into it.  You pass in the name of a child Alias (needs to be mapped and defined ahead of time) so that, at run time, you can check to see if the object referenced by that Alias is actually present in memory in your operating system.  Before you can do ANYTHING with that object, we need to make sure it's there... kind of like making sure you instantiate someObject before you try and use its properties.  So, you call WaitAliasChild as part of your detection logic.  For example, this code actually works properly if the object does not exist because we first check to see if it IS an object of the correct type before we try and reference it.

    var someObject;
    
    class myObject{
        constructor(){
            this.Exists = true;someObject
            this.someText = 'I think therefore I am';
        }
    
    }
    
    
    function testObject(){
    
    
        if (!(someObject instanceof myObject)){
            Log.Message('It does not think therefore it is not')
        }
        else {
            
            if (someObject.Exists){
                Log.Message(someObject.someText);
            }
        }
    }

     

    See?  This is why TestComplete "waits" for onscreen components before attempting to interact with them.  It's to make sure that it actually is present in memory before you access any of it's properties.