Forum Discussion
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 ....
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