FindChild taking a long time TC12
The software I am testing is written in VB6 and has the issue whereby the object names can change every time it is compiled making mapping impossible. To get around this I use the the FindChild method to find the objects every time I need to call them (yes it's tedious) I came up with the following function (VBScript), I also included a timer for debugging which I comment out when not developing.
Function Find_ChildObj(VBobj, Idx, Parent, DepthVal)
Dim StartTime, EndTime, Elapsed
If DepthVal >= 0 then
Depth = DepthVal
Elseif isNull (DepthVal) Then
Depth = 4
End If
StartTime = aqDateTime.Time
If isNull (Idx) and isNull (Parent) Then 'When Index and Parent are Null
PropNames = Array("Name", "Visible")
PropValues = Array(VBobj,True)
Set P = Sys.WaitProcess("Base App Name")
Set child = p.FindChild(PropNames, PropValues, Depth, True)
'Log.Message("Idx and Parent parameters Null")
ElseIf isNull (Idx) Then 'When Index is Null
PropNames = Array("Name", "Visible")
PropValues = Array(VBobj, True)
Set P = (Parent)
Set child = p.FindChild(PropNames, PropValues, Depth, True)
'Log.Message("Idx Parameter Null")
ElseIf isNull (Parent) Then 'When Caption is Null
PropNames = Array("Name", "Index", "Visible")
PropValues = Array(VBobj, Idx, True)
Set P = Sys.WaitProcess("Base App Name")
Set child = p.FindChild(PropNames, PropValues, Depth, True)
'Log.Message("Parent Parameter Null")
Else
PropNames = Array("Name", "Index", "Visible") 'All values present
PropValues = Array(VBobj, Idx, True)
Set P = (Parent)
Set child = p.FindChild(PropNames, PropValues, Depth, True)
'Log.Message("No Null parameters")
End IF
EndTime = aqDateTime.Time
Elapsed = aqDateTime.TimeInterval(StartTime, EndTime)
Parent = CStr(P.FullName)
If Not child.Exists then
log.Error "Unable to locate child obj of " & Parent, "", pmNormal, LogStyle ("TestFail")
GeneralEvents_OnLogError
Else
Set Find_ChildObj = eval(child.FullName)
CName = child.FullName
log.message(Elapsed &" to find " &CName)
End If
End FunctionThis is called in each script with the following
Set ChildObj = Find_ChildObj ("*Partial of Child Name*", ChildIndexNumber, ParentObjectName, Depth)I can cascade this, so I can find the Parent and then the child so the ChildObj becomes the ParentObjectName in the next call, which makes finding some objects a lot quicker.
What I am finding is that in one case an object can be found quickly but in the very next test, called in exactly the same way from on the same screen of the app in test, It can take a very long time to find the object sometimes sometimes a minute or minute and a half.
If I take the Depth down to 1 making sure the parent object is included in the call, it can help but then this can throw up another bizarre situation where even though the child is with in depth 1 the child object cannot be found at all and if I increase the depth to 2 it is found but takes a long time again. If I try to store the object then I sometimes have the error that the object does not exist.
Generally the function and call works fine and objects are found within a couple of seconds if not milliseconds.
Can any one shed some light as to why I am seeing inconsistent performance and success in the call.
Btw feel free to use the function if it's of any help.
Many thanks