Forum Discussion

tristaanogre's avatar
tristaanogre
Esteemed Contributor
5 years ago

Pro-Tip: Why wait?

The question has been asked recently "why wait for an object if I already know it doesn't exist?"

 

The answer: because you DON'T know. When it comes to onscreen objects, when you tell TestComplete to interact with the object, the first thing it has to do is determine if that object is present in memory.  You can't access ANY properties or methods or ANYTHING on that object if the object is not memory resident.

Here's kind of a mock up example that demonstrates this in JavaScript.  This is by no means as robust as the WaitAliasChild or WaitChild logic of TestComplete but it demonstrates, essentially, what is being done internally.  Basically, the child object of some object, we want to do something with it.  But we need to first make sure that it is actually an object of the correct object type before we can start interacting with it.

 

class myObject{
    constructor(){
        this.Exists = true;
        this.someText = 'I think therefore I am';
    }
    waitMyObject(objectToCheck){
        objectToCheck = eval('this.' + objectToCheck);
        if(!(objectToCheck instanceof myObject)){
            objectToCheck.Exists = false;
            return objectToCheck;
        }
        else return objectToCheck;
    }

}
var someObject = new myObject();

function testObject(){

    someObject.childObject = {};
    if (!someObject.waitMyObject('childObject').Exists){
        Log.Message('It does not think therefore it is not')
    }
    else {
            Log.Message(someObject.childObject.someText);

    }
}

This is analogous to the WaitAliasChild methodology.  We KNOW we want to interact with a child object of one of our mapped Aliases.  But, before we do, we want to make sure that the referenced child object can be located in memory. So, we call the appropriate Wait method.  

 

Hope this helps explain this concept for some of you new users out there.