QTP methods and script for reading object properties

In the previous Chapter, I had written about Object Spy.

For using Object Spy, we need to point the Object Spy pointer on the Object.
i-e We can read the properties manually only. And it can be done in the design time only.
In this post, I am going to write about reading the properties of any Object in the application using scripting (i-e programmatically in run-time)

QTP is having below methods.

GetTOProperty– This method returns the value of the property from the test object’s description, i.e., the value used by QTP to identify the object. In other words the list of properties stored the Object Repository. If the property is not part of the test object’s description, a warning will be issued by QTP.

GetTOProperties – This method is similar to GetTOProperty, but it will list all/collection of properties and their values.

It can be used as below to get all the Test Object properties and their values in “Submit” button of “Login” window in a vb application.

Set theTestObject = VbWindow(“Login”).VbButton(“Submit”)

Set Props = theTestObject.GetTOProperties

PropsCount = Props.Count

For i = 0 To PropsCount – 1

PropName = Props(i).Name

PropValue = Props(i).Value

MsgBox PropName & ” = ” & PropValue


Set theTestObject = VbWindow(“Login”).VbButton(“Submit”)
Set Props = theTestObject.GetTOProperties
PropsCount = Props.Count
For i = 0 To PropsCount – 1
PropName = Props(i).Name
PropValue = Props(i).Value
MsgBox PropName & ” = ” & PropValue

GetROProperty – It will be used to get the value of an object property during runtime, such as the current list/combo item selection, page title, or the text in a WebEdit, or the size (width & height) of an object.

SetTOProperty changes the value of a test object property. Changing the property won’t make any change in the Object Repository, but it will just affect the way QTP identifies the object during runtime. Actually, this changes the properties of the temporary copy of the object stored in RAM by QTP.

i-e QTP is having the methods GetTOProperty,GetTOProperties and SetTOProperty for handing Test Objects.

And, it is having SetTOProperty method for handing Run-time object.
Obviously it can not have method SetROproperty, because QTP script should not change the actual objects (But still we can do it using “Object”. I will write a separate post about it later)

But it can have a method something like getROproperties. As of now, QTP is not having such a method.

So, we can read all RO properties from windows registry.
For example, below piece of code can read the name of properties for “Page” object from the registry.

Const HKEY_LOCAL_MACHINE = &H80000002

Set oReg = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv”)

SKeyPath = “SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\page\Properties”

oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyPath, arrNames

sNames = “List of Properties:” & vbNewLine

For i = 0 to UBound(arrNames)

sNames = sNames & arrNames(i) & vbNewLine


Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv”)
sKeyPath = “SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\page\Properties”
oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyPath, arrNames
sNames = “List of Properties:” & vbNewLine
For i = 0 to UBound(arrNames)
sNames = sNames & arrNames(i) & vbNewLine

After reading the properties, the script can read each property name from the array “arrNames” and get the run-time object value using GetROproperty method.You can refer below piece of code.

Set TestPage = Browser(“Google”).Page(“qualitypoint”)

For i = 0 to UBound(arrNames)

sNamesRO = sNamesRO & arrNames(i) & “: ” & TestPage.GetROProperty(arrNames(i)) & vbNewLine


MsgBox sNamesRO

Leave a Reply