cancel
Showing results for 
Search instead for 
Did you mean: 

What's the best way to wait for an object to be closed?

SOLVED
robertmarsh
Occasional Contributor

What's the best way to wait for an object to be closed?

Hi, i've inherited some test cases and although they pass, I am getting the dreaded 'An object recognition hint' warning.

 

The code in question is waiting for an object to not exist before continuing:

// Wait until the template window is not shown anymore. 
Rm_App["NewTemplate"]["WaitProperty"]("Exists",false,200000);

I'm guessing the WaitProperty method is not the correct method to use here and hence why I'm getting the warning, or maybe it is and I just need to add some code around it to utilise it properly?

 

So my question is what is the best practice to use in it's place to wait for an object to finish it's job and close before the test continues?

 

Notes: Code being used is C#Script, and i'm pretty new to the coding world so be gentle. Smiley Happy TIA

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: What's the best way to wait for an object to be closed?

I don't like using WaitProperty for the "Exists" property...  if you think about it, the WaitProperty method is being called off the object you're looking to see if it exists.  If that object does not actually exist, how you can call a method?

 

What I usually do for "wait for not exists" scenario us use WaitChild to find the object (or FindChild or something similar) and then check the exists property of the resulting object and then loop until it no longer exists.

 

Something like:

 

// Wait until the template window is not shown anymore. 
while !RM_App["WaitAliasChild"]("NewTemplate, 500).Exists
    Delay(500)

Caveat: If something goes wrong, this can be an infinite loop. So, I often add a counter to put a limiter on the loop to limit how many times it loops.  But hopefully this should help get you in the right direction.


Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available

View solution in original post

3 REPLIES 3
tristaanogre
Community Hero

Re: What's the best way to wait for an object to be closed?

I don't like using WaitProperty for the "Exists" property...  if you think about it, the WaitProperty method is being called off the object you're looking to see if it exists.  If that object does not actually exist, how you can call a method?

 

What I usually do for "wait for not exists" scenario us use WaitChild to find the object (or FindChild or something similar) and then check the exists property of the resulting object and then loop until it no longer exists.

 

Something like:

 

// Wait until the template window is not shown anymore. 
while !RM_App["WaitAliasChild"]("NewTemplate, 500).Exists
    Delay(500)

Caveat: If something goes wrong, this can be an infinite loop. So, I often add a counter to put a limiter on the loop to limit how many times it loops.  But hopefully this should help get you in the right direction.


Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available

View solution in original post

robertmarsh
Occasional Contributor

Re: What's the best way to wait for an object to be closed?

Thanks Rob, i had also looked at using the VisibleOnScreen method but used this instead with a loop counter 🙂

AlexKaras
Community Hero

Re: What's the best way to wait for an object to be closed?

Hi,

 

Robert's reply is absolutely correct for the piece of code you've provided.

Indeed, provided code basically says this to TestComplete: "Get a NewTemplate object within the Rm_App application and check the value of object's Exist property". Obviously, if the object does not exist, than the property does not exist either.

 

Another case, if the code operates with the saved reference to some object. In this case, when the referenced object is destroyed, TestComplete handles this and invalidates all its properties and methods except the Exist property which is assigned the False value. And this is what can be used and be waited for.

Sample pseudo-code to illustrate the above:

var aTemplate = Rm_App["NewTemplate"];

// ...

// do something with the object

// ...

aTemplate.Close();

aTemplate["WaitProperty"]("Exists", false, 200000);

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements