preload

TestComplete – Wait then Find

Posted by Albert Gareev on Dec 07, 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 about WaitChild method

Let’s start with the example.


Dim boolRC
Dim IEProcess, IExplore
Dim PropNames, PropValues, arrComboBox
Dim Page1, Page2
Dim objForm, objLink, objComboBox

'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", "http://www.google.ca/")
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
Set Page2 = Sys.Process("iexplore").WaitChild("Page(""http://www.google.ca/advanced_search?hl=en"")", 1000)
boolRC = Page2.Exists 'Returns true

'Find Web Page by generic object name
Set Page2 = Sys.Process("iexplore").WaitChild("Page*", 1000)
boolRC = Page2.Exists 'Returns true

We agreed that idly waiting for hard-coded amount of time is inflexible and unreliable synchronization approach. Luckily, we can let TestComplete to wait while checking if the object has appeared.

Note the line 47.  We do not supply property name / property value recognition properties but Page2 will be successfully found. That’s because WaitChild method simply accepts object’s name. You can find it out through the Object Properties Viewer.

That means, however, that we have to know it ahead of time; to inspect each GUI object at least once while creating test scripts. And what if another, unexpected page will appear instead?

To address such issues, implement flexible, 2-step synchronization process. First, wait for a page to appear (see line 51). Then try to identify it, using description properties, to find out if that is the page you expected.

You can also build your own, custom recognition / synchronization function, and we will talk about that in the next post in this series.


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.