Forum Discussion

robertmarsh's avatar
robertmarsh
Occasional Contributor
5 years ago
Solved

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. :smileyhappy: TIA

  • 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.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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.

    • robertmarsh's avatar
      robertmarsh
      Occasional Contributor

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

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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);