Forum Discussion

doran_snider's avatar
doran_snider
New Contributor
14 years ago

WaitSwingObject not working?

I used the script extension "Wait for Object" I found here, http://blog.smartbear.com/software-quality/bid/170163/, to insert an if statement to wait for an object to appear before proceeding.



I thought the intention of this was to control flow of the playback, as we don't know how long some things take in the application.  In my case, it is on loading.  I start the app, choose a file to load, then the application takes some amount of time to load to the application's desktop.  Because this loading process takes a variable amount of time, I thought this "Wait for Object" script extension, utilizing the WaitSwingObject method would be perfect.



If (Not Aliases.java.wndSunAwtFrame1.RibbonRootPane.null_layeredPane.null_contentPane.ScrollPane.Viewport.ProjectToolDesktopPane.WaitSwingObject("JInternalFrame", -1).Exists) Then



My problem is this statement fails with "object does not exist", completely defeating the purpose of this method in the first place. I know the object doesn't exist yet, the application is still loading; that's why I'm using this method.  I want my script to wait an infinite amount of time to let the application finish loading before moving on. I used a timeout of -1 for "infinate", but it still fails within 3 seconds.  I increased the method invoke timeout to 50000ms in the project Open Applications->General settings, but this didn't have any affect.



If I don't use this WaitSwingObject method in my if statement, then my script fails on the next step of clicking a dropdown because it can't find the dropdown (because my app hasn't finished loading yet).



The object in my If statement is in my NameMapping and when I use object spy on this object, it does indeed highlight it in my application (of course the application has to finish loading before it "exists").



Also, I used the Wait for Object script extension during recording to say, "wait for this object to exist an infinate amount of time".



Any ideas?

1 Reply


  • Hi Doran,


     


    I suppose, you are calling the WaitSwingObject method from a wrong object. As your application is loading at the beginning of the test, call the method of the main window. I think, the code should be modified in the following way (I'm using the WaitAliasChild method as wndSunAwtFrame1 is the mapped name):


    If (Aliases.java.WaitAliasChild("wndSunAwtFrame1", -1).Exists) Then 


    ...


     


    BTW, the script extension you are using is obsolete. TestComplete 9 has built-in features that you can use to wait until the object is fully loaded. Please read the "Waiting for an Object, Process or Window Activation" article for more information.