preload

TestComplete – FindChildSync

Posted by Albert Gareev on Dec 13, 2010 | Categories: GUI RecognitionSource codeTestCompleteWeb

Parent page: GUI Recognition with TestComplete

TestComplete provides a whole set of run-time GUI recognition functionalities, based, however, on the same approach: recognition by property values and/or location of the object in internal hierarchy. In addition to methods that immediately return a child object, if it’s available, there are others, that help finding objects that only about to appear – and this way you can create parameterized and flexible synchronization points.

Today’s post is an example of using custom recognition / synchronization function

Let’s start with the example. If you want to execute the code, make sure you also copied custom function FindChildSync provided in the second section.

Dim boolRC
Dim IEProcess, IExplore
Dim PropNames, PropValues
Dim Page1, Page2
Dim objLink

'Close browser
PropNames = Array("processname", "index")
PropValues = Array("iexplore", 1)
Set IEProcess = Sys.FindChild(PropNames, PropValues, 1, True)
If IEProcess.Exists then
IEProcess.Close(10000)
End if

'Open browser and navigate to the web-site
Set IExplore = TestedApps.iexplore
IExplore.Params.SimpleParams.CommandLineParameters = "http://www.google.ca/"
Call IExplore.Run(1, False, 5000)

'Find First Web Page Object
PropNames = Array("objecttype", "url")
PropValues = Array("page", <a href="http://www.google.ca/">http://www.google.ca/</a>)
Set Page1 = Sys.Process("iexplore").FindChild(PropNames, PropValues, 1, True)
If Not Page1.Exists then
Exit Sub
End if

'Find Second Web Page Object
PropNames = Array("objecttype", "url")
PropValues = Array("page", "http://www.google.ca/advanced_search?hl=en")
Set Page2 = Sys.Process("iexplore").FindChild(PropNames, PropValues, 1, True)
boolRC = Page2.Exists 'Returns False
'Find Web Link Object
PropNames = Array("tagName", "namePropStr")
PropValues = Array("A", "advanced_search*")
Set objLink = Page1.FindChild(PropNames, PropValues, 10, True)

If Not objLink.Exists then
Exit Sub
End if

objLink.Click

boolRC = Page2.Exists 'Returns False

'Find Web Page by specific object name
PropNames = Array("objecttype", "url")
PropValues = Array("page", "http://www.google.ca/advanced_search?hl=en")
Set Page2 = FindChildSync(Sys.Process("iexplore"), PropNames, PropValues, 1, 10)
boolRC = Page2.Exists 'Returns true

At the very end, line #50 (I highlighted it for you), you can see call to a custom function. Unlike WaitChild built-in method in TestComplete, it uses description properties to identify an object.

Below you can find description and source code of the function.

FindChildSync

Description

Validate and initialize passed in parameters. – Start timer. – Begin identification loop.
Use FindChild standard method to attempt locating child GUI element. Repeat attempts until object is found or timeout is reached.

Returns GUI object’s reference or Nothing – if search wasn’t successful.

Implementation

Public Function FindChildSync(ByRef objGUIParent, ByRef PropNames, ByRef PropValues, ByVal intDepth, ByVal intSyncMax)
Dim intStopWatch
Dim objGUIElement

'Init
If objGUIParent is Nothing Then
Set FindChildSync = Nothing
Exit Function
End If

If Not objGUIParent.Exists Then
Set FindChildSync = Nothing
Exit Function
End If

If (Not isArray(PropNames)) OR (Not isArray(PropValues)) Then
Set FindChildSync = Nothing
Exit Function
End If

If Not isNumeric(intDepth) Then intDepth = 0
If intDepth < 0 Then intDepth = 0

'Set timer
If intSyncMax < 0 Then intSyncMax = 0
intStopWatch = Time()

'Loop until child object appeared or timeout reached
Do While True

On Error Resume Next
Set objGUIElement = objGUIParent.FindChild(PropNames, PropValues, intDepth, True)
On Error GoTo 0

If objGUIElement.Exists Then
'Object's found
Exit Do
Else
'Keep trying
End If

'Exit by timeout
If DateDiff("s", intStopWatch, Time()) > intSyncMax Then
Set FindChildSync = Nothing
Exit Function
End If

Loop

Set FindChildSync = objGUIElement

End Function


  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.