cancel
Showing results for 
Search instead for 
Did you mean: 

Pro-Tip: Why wait?

Highlighted
Community Hero

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
1 REPLY 1
Community Manager

Re: Pro-Tip: Why wait?

I like your detailed explanation, Robert!

Thanks a lot.

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors