Forum Discussion
the thing is you can't do this on the object if the object does not exist. That's why you have to use the method Exists not on the object itself, but using the waiting metods waitwindow, waitproc...
Did you try the WaitProperty method?
- tristaanogre10 years agoEsteemed Contributor
Break up your statement... you are combining "obj.Exists" in the same boolean expression as a number of other properties. However, if the object does not exist, none of those other properties are valid.
Start with checking if the obj.Exists... be sure to use a "WaitNNN" method of some sort to return your obj value. Then test for Exists. If the Exists test passes, THEN proceed with the other tests you're looking for.- Colin_McCrae10 years agoCommunity Hero
Yep.
What Robert said.
You need to wait until it exists first. (Or doesn't) And then act accordingly.
You can only check the other stuff once it exists. So you need to split this into multiple steps.
Even then, I have all this kind of thing inside try/catch routines. From experience, automated tests need to be bomb proof, or people lose faith in them. Even if it fails out massively, I still want it to get to the end and tell me that. Not come in the next morning and find it crashed, frozen, or stuck in an eternal loop it can never get out of ....
- mes607310 years agoContributor
I have found that it is better to be active, than reactive, whether dealing with a parent or child object. Identifying an object by 'waiting' using either the default timeout of the 'Exists' method, or explicitly specifying timeout values via the WaitProperty method is very reactive. In either case, rather than using some arbitrary timeout value, TestComplete provides the Sys process list to find a parent object, or the object list for child objects. Thus, I find it more economical to use a loop limited by a max count and a finite delay (999 milliseconds for example) to identify an object's parent then use methods such as the FindChild or FindAllChildren methods to ensure I am dealing with the correct object.
''' <summary>FindChildDialog</summary> ''' <param Type="String">[ByVal] parentName</param> ''' <param Type="String">[ByVal] wndCaption</param> ''' <param Type="Interger">[ByVal] intMax</param> ''' <returns type="Boolean">True if successful, otherwsie False</remarks> ''' <remarks>Search for child dialog with specified caption. Function fails if ''' the requried child is not located within the max number of retries</remarks> Function FindChildDialog(parentName, caption, intMax) FindChildDialog = False Dim parent, dlg, dlgs, i, msg, wndCaption Dim count : count = 0 Dim delay : delay = 999 Dim wndClass : wndClass = "WindowsForms10.Window.8.app.*" Do Sys.Refresh Set parent = Sys.WaitProcess(parentName, delay) If parent.WaitProperty("Exists", True, delay) Then parent.Refresh() dlgs = parent.FindAllChildren("WndClass", wndClass, 1, True) For i = 0 To UBound(dlgs)
Set dlg = dlgs(i)
If aqObject.IsSupported(dlg, "WndCaption") Then
wndCaption = dlg.WndCaption ' use aqString.Compare for exact match or use aqString.Find ' if trying to identify object based on use of wildcards If aqString.Find(wndCaption, caption, 0, False) <> 0 Then If dlg.WaitProperty("Visible", True, delay) Then msg = aqString.Format("The '%s' windows dialog is visible", wndCaption) Log.Checkpoint msg,, pmNormal,, Sys.Desktop.ActiveWindow FindChildDialog = True End If End If End If Next End If
count = count + 1 Set parent = Nothing Loop Until (FindChildDialog = True) Or (count < intMax) End Function ' FindChildDialod