Forum Discussion

manish_bansal_1's avatar
manish_bansal_1
Occasional Contributor
11 years ago

How to wait for an object exists for till custom timeout?

Hi Guys,
It have been a while now using TestComplete over QTP, but still am struggling to find the best ways to wait for an object exists.

 

Well, The exists function does the job but not perfectly, becuase it has to wait till the time we have setup globally, in the project settings.

the main issue is TestObject.Exists (does not accepts timeout).

 

Someone from the community friend have suggested me to use "WaitProperty", but the fact is WaitProperty can not be used on the objects which are not available. (or disposed/proxy objects)

 

My requirement is I want to move ahead as soon as a specific Window say "mywin" gets disappear (sometime this window take 1 sec, sometime 10 or sometimes even more)

In this situation I cant even use "exists" function on "mywin" window object in loop, becuase as soon as this window will get disapear, TestComplete will wait for 30 sec (global time given in the settings)

 

 

A simple question to TC dev/design team, what is the harm in extending .exists function to accept timeout in sec/millisec ?

nevertheless, guys please help me find out the workaround.

 

 

Thanks,

Manish Bansal

 

 

 

 

 

4 Replies

    • manish_bansal_1's avatar
      manish_bansal_1
      Occasional Contributor

      Well, we should never use hard coded wait/delay... for the best performance, delay's should be used inside loops only.

       

  • boroop's avatar
    boroop
    Occasional Contributor

    Manish,

     

    If your operation is being run from within a keyword test you can add a column to your test that allows you to use a different timeout value.

     

    Open your keyword test and right click on the headers for the columns (Item, Operation, Value, etc.). Pick Field Chooser from the menu that appears. This will open a new small dialog that has Auto-wait timeout in the list (which likely only contains this one item). Drag and drop Auto-wait timeout onto the column headings and drop it in whatever location you like.

     

    Now you will see a new column which contains [Default] for every operation. Single click one of those [Default] values twice (don't double click, single click slowly - twice to make it editable) and then type in the ms value you'd like to wait.

  • Manish, this is one of the issues that bothered me as well. I don't like using .exists with mapped objects for that very reason. I've found that the Find method is significantly more reliable. Unfortunately, it doesn't have a built-in wait functionality either. So, I ended up writing my own wait function:

    function waitWhile(condition, msg, timeout)
        dim t
        t = 0
        do While eval(condition) and t <= timeout 
            delaytext = t & " of " & timeout & " seconds passed waiting for " & msg
            delay 1000, delaytext
            t = t + 1
        loop
        if t <= timeout then 
            waitWhile = true
        else
            waitWhile = false
            log.event "Timeout expired waiting for " & msg
        end if
    end function

     An example call to this would look like:

    call waitWhile("aliases.pageObj.find(""name"", ""elementname"", 4, true).exists", "element to appear", 30)

     So this waits for up to 30 seconds for the object "elementname" to exist within for first 4 tree levels from pageObj. It will also change the indicator to say what it's waiting for (msg) and for how long. In the end, it returns a boolean for whether it hit the timeout period or not.

     

    Hope this helps.