cancel
Showing results for 
Search instead for 
Did you mean: 

A Better Way to Find Objects

Highlighted
Occasional Contributor

A Better Way to Find Objects


I'm working on ways for TestComplete to find objects by looping until they actually exist, since the WaitWinFormsObject and WaitMSAAObject and so forth, don't seem to work very well and I don't want to have timed waits. And infinite waits are useless when Testcomplete can't find the object 25% of the time (this leads to TC looping for hours until I stop the tests).





A few ideas I've tried:

1. A looping refresh until the item .exists (This works but posts an error to the log (.exists is possibly the most useless property of any object as it will error because the object does not exist... duh!)

***If anyone knows of a way to suppress this error, please let met know 🙂 ***





2. Looping until the childcount of the parent object is >= number (this essentially will wait for the object tree to be created, if only I could get it to work)





I'm lost on further ideas...
1 REPLY 1
Highlighted
Community Hero

RE: A Better Way to Find Objects

Untested, try something like this (DelphiScript):



function WaitForObject(ObjectName, WaitTime: integer = 60): boolean;

{WaitTime is in seconds}



var

    AUT: OleVariant;

    I: Integer;



begin

AUT := Sys.Process('MyApp');

for I := 1 to WaitTiime do begin

    Result := AUT.WaitVCLObject(ObjectName, 1000).Exists;

    if Result then break;

    end;

end;




The key to the "Exists" property is that you need to have an object for which to call the exists property.  So, you HAVE to use a Wait method of somesort.  The Wait method, if it does not find the object, returns an empty stub where the Exists property is False so you never get the error you indicated.



The above code may not work EXACTLY for you, but this is a way to create a custom wait routine.


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
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors