Forum Discussion

whuang's avatar
whuang
Regular Contributor
5 years ago
Solved

Using Exists method in a if statement

Hello,

 

I have a if statement that checkes whether an object exists, if the object_A exists then set it as a wrapper, if object_A doesn't exist, then Object_B will exist for sure, so then set object_B as the wrapper. But when object_A doesn't exist, TC keeps waiting, until the default wait time runs out. Is that how it works? Is there any method I can use to check and switch to object_B if A is not found without waiting? Both object_A and B are mapped.

 

If Object_A.Exists Then

set wrapper = Object_A

Else

set wrapper = Object_B

End If

 

I also tried namemapped the parent of the object that I want to check, then I do If Object_Parent.WaitAliasChild("Target_Object",0) Then xxxx, but it returns the parent object doesn't have a child with the target object name.

 

Thanks


  • whuang wrote:

    Is there any method I can use to check and switch to object_B if A is not found without waiting?


    No, but you can limit the wait time by using a WaitNNN with a very short timeout e.g

    Object_A = Object_A_Parent.WaitAliasChild("Object_A",100);

     

    This of course assumes that Object_A_Parent exists...

4 Replies


  • whuang wrote:

    Is there any method I can use to check and switch to object_B if A is not found without waiting?


    No, but you can limit the wait time by using a WaitNNN with a very short timeout e.g

    Object_A = Object_A_Parent.WaitAliasChild("Object_A",100);

     

    This of course assumes that Object_A_Parent exists...

    • whuang's avatar
      whuang
      Regular Contributor

      Thanks RUDOLF_BOTHMA Marsha_R , I ended up using Object_A_Parent.WaitChild(Object_A,0).Exists, whenever I used WaitAliasChild, it always returned me the parent object doesn't have a child with Object_A.

      Also can WaitChild check grandchild object or even deeper? Looks like it can only check the child object 1 level under it.

      • RUDOLF_BOTHMA's avatar
        RUDOLF_BOTHMA
        Community Hero

        No, WaitChild and WaitAliasChild is limited to the single child tier.  Same goes for all the WaitNNN methods.  If you need to traverse multiple tiers and you don't know the structure - or it's unreliable - you will have to use Find methods (FindChild, FindChildEx, FindAll).  The winner would be if you can reliably Map & Alias them, since it's faster, but sometimes Find methods are unavoidable.  Find methods can also accept a timeout as parameter, so you can make this short as well.  It will return early the moment it finds the object though, so you can afford to not make it TOO short and not allow TC to find it.  The more specific you can be with your property values for your find, the better, so try and get those ientification details as specific as possible.

         

        Seperate thought.  You may just be going too fast for TC to keep up.  That is where Wait is better than Find.  You can however, in web applications, also be running into AJAX issues.  TC caches the mappings, so when AJAX changes the web page, TC doesn't always know - it has the old page layout cached or doesn't know about the child yet.  In this case, consider using Refreshmapping/RefreshMappingInfo() on the parent object before trying to find the child

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    You'll want to take a look at this:

    https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html

     

    Also I suggest using your equivalent of the statement below.  If it happens that Object B isn't there, this is a better way to catch the error, rather than just letting the test fail.

     

    If Object_A.Exists Then

    set wrapper = Object_A

    Else

    If Object_B.Exists Then

    set wrapper = Object_B

    Else

    *Post Error = Object_A and Object_B are both missing*

    End If