Thursday, November 20, 2008

QTP Script 18 - How to retrieve all direct children of the specified parent object and their properties from Shared Object Repository?

Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
RepositoryFrom.Load "C:\Program Files\HP\QuickTest Professional\Rep2.tsr"

Function EnumerateAllChildProperties()

'The following function recursively enumerates all the test objects directly under a specified parent object. For each test object, a message box opens containing the test object's name, properties, and property values.

'Retrieves all direct children of the specified parent object. If you do not specify a [any] object, all top-level objects in the object repository, including checkpoint and output objects, are retrieved.

Set TOCollection = RepositoryFrom.GetALLObjects()
msgbox TOCollection.count
For i = 0 To TOCollection.Count - 1
Set TestObject = TOCollection.Item(i)

'GetLogicalName Retrieves the name of the specified object. It requires an object whose name you want to retrieve.

Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine
msgbox Msg

'GetTOProperties Returns the collection of properties and values used to identify the object.

Set PropertiesCollection = TestObject.GetTOProperties
msgbox PropertiesCollection.count
For n = 0 To PropertiesCollection.Count - 1
Set Property = PropertiesCollection.Item(n)
Msg = Msg & Property.Name & " - - " & Property.Value & vbNewLine
MsgBox Msg
End Function