preload

TestComplete – Couldn’t Find and Fine About It

Posted by Albert Gareev on Nov 23, 2010 | Categories: GUI RecognitionSource codeTestCompleteWeb

Parent page: GUI Recognition with TestComplete

First of all, a short note to those readers who like to rush into conclusions.
This post is about a feature, not bug.

Here I continue exploring TestComplete GUI recognition capabilities with code example. The previous two posts (here and here) were about Find, FindChild, and FindAllChildren methods. Today I want to show the case when these methods appear not working, find out why it’s valid, and how to properly work it out.

Let’s start with the code 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

aqUtils.Delay 2000

boolRC = Page2.Exists 'Still returns False
  '

'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 'Finally, Returns True
  'See explanation why below

First of all, note the line 49 (it’s highlighted). aqUtils.Delay 2000 statement there is a primitive synchronization point: we give the web browser 2 seconds to reload the page by making the script idle for that amount of time. Not the best way for a properly created automation, but we will talk about synchronization in the subsequent posts.

Second, note line 51. While the Web Page (“Advanced Search”) surely exists on the screen at that point of time during execution, .Exists returns False. That is critically important!

With Find/FindChild methods you can not map GUI objects if they are not available.

The explanation is simple though. If a parent object does not have a child with description properties matching the specified set, it has nothing to return. The object, that is still returned is just a “stub” object which has only .Exists property which is always False. For identification of objects which about to appear TestComplete has another family of methods – WaitChild, WaitNamedChild, and other. We will try them in the next post.


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.