QTP Descriptive Programming - How To Get Number of Objects: Google Sets
QTP Descriptive Programming - How To Get Number of Objects: Google Sets
I'm going to explain and show QTP Descriptive Programming (DP) through Google Sets site:
Answer: QTP DP is a run-time processing of objects which are not located in QTP Object
Repository.
I've created new QTP script which starts with http://labs.google.com/sets page.
This QTP script is simple enough:
Set Desc = Description.Create()
Desc("micclass").Value = "WebEdit"
Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)
As you can see, it works correctly and returns correct number of Edits on a page.
I'm going to explain this QTP script and answer the following question:
To specify that we want identify all Edits on browser's page I use "micclass" property:
Desc("micclass").Value = "WebEdit"
Note: the "mic" prefix in "micclass" stands for "Mercury Interactive Constant".
Since we created Description object for all edit boxes, we can use this description to get all
specified objects ( = edit boxes).
The next step returns the collection of all child objects (i.e. edit boxes) contained within the
page:
Set Links = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)
To get the number of found objects in a returned collection, we use Count property:
MsgBox "Number of Edits: " & Links.Count
Also, we can use the same code to get number of others objects - Links, Images, Buttons, etc.
For that I modified QTP script:
Function GetAllSpecificControls(Page, MicClass)
Set Desc = Description.Create()
Desc("micclass").Value = MicClass
Set GetAllSpecificControls = Page.ChildObjects(Desc)
End Function
Function GetAllEdits(Page)
Set GetAllEdits = GetAllSpecificControls(Page, "WebEdit")
End Function
Function GetAllButtons(Page)
Set GetAllButtons = GetAllSpecificControls(Page, "WebButton")
End Function
Function GetAllLinks(Page)
Set GetAllLinks = GetAllSpecificControls(Page, "Link")
End Function
Function GetAllImages(Page)
Set GetAllImages = GetAllSpecificControls(Page, "Image")
End Function
You can compare the result with the initial web page (see first image in the present article) and
verify that QTP Descriptive programming works correctly - it returns correct numbers of objects.
Summary: