Forum Discussion

eccramer's avatar
eccramer
New Contributor
14 years ago

WaitWinFormsObject not reliably detecting objects.

My team is testing a .NET application, so the WaitWinFormsObject method is used quite frequently in our tests. However, the WaitWinFormsObject method has not been finding some objects reliably on the first try, and has to be invoked twice (no matter what timeout specified) to find a windows form object. This has been happening intermittently, where TestComplete can see the object in the object browser, but WaitWinFormsObjet cannot resolve a handle to the object on the first invocation. It will however, find the object immediately if it is invoked again. For example:



//This will correctly find the process

var process = Sys.WaitProcess("OurApp", 1000);



//This will not find the WinFormsObject named FrameForm no longer how long the interval is.

var FrameFormHandle = process.WaitWinFormsObject("FrameForm", 36000);



However, if we invoke it this way:



//This will correctly find the process

var process = Sys.WaitProcess("OurApp", 1000);



//This will not find the WinFormsObject named FrameForm no longer how long or short the interval is.

var FrameFormHandle = process.WaitWinFormsObject("FrameForm", 1000);



if(!FrameFormHandle.Exists) {

    //This WILL find the WinFormsObject named FrameForm IMMEDIATELY

    FrameFormHandle = process.WaitWinFormsObject("FrameForm", 1000);

}



I've verified that the FrameForm object exists in the object browser before invoking WaitWinFormsObject, so this is not a race condition situation where the object does not exist when the method is first invoked. And again, this is intermittent issue, where sometimes TestComplete WILL correctly find the FrameForm object on the first try. There is no apparent reason for TestComplete not to find the object when first invoked, and I would prefer not to have to call WaitWinFormsObject twice. Sometimes it works as it's supposed to, and sometimes it doesn't. It almost seems like it fails to find the object on the first try more often than it correctly finds it.



Is there an issue in the way we're invoking the WaitWinFormsObject method, or is this an issue with the method itself, or is it some other issue.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Is it possible, in your application, that you have more than one object that might be memory resident that is named "FrameForm"?  



    Something else:  I had similar problems with VCLObjects back in the day in a Delphi application and, what I found was useful, was, on the Process object, call the "refresh" method before calling the "WaitVCLObject" method.  Try inserting a Sys.Process("MyApp").Refresh before the calls for that particular object.
  • eccramer's avatar
    eccramer
    New Contributor
    I just doublechecked to see if there is more than 1 FrameForm object, but there isn't. However, your Sys.Process("MyApp").Refresh idea is promising. I'll either edit this post, or reply to this thread if the problem persists. If it does persist, I'll try to gather more pertinent information about why it might be behaving this way.