Relevant Codes (by Anshoo Arora)

A Test Development Resource for HP QuickTest Professional.

GetROProperties (Custom)

by Anshoo Arora on December 10, 2009

There have been numerous threads/discussions about the lack of GetROProperties, which is not available with the QuickTest package. There is GetTOProperty, GetROProperty, GetTOProperties and until now, GetROProperties was the only method missing from the pack. Now, its available and it works just like GetTOProperties does. This article shows how the method is created, and there are 2 examples at the end of this article which demonstrate its usage.

I would strongly recommend automation developers using this method also read the article RegisterUserFuncX: Register Methods To All QTP Objects Automatically, which can be used to register GetROProperties to all QuickTest Objects.

To replicate the way GetTOProperties works, this method uses a RecordSet object to store the properties and their corresponding values. The descriptions of objects are retrived from the Registry, and because not all keys (properties) are present there, you would have to manually create the missing keys. The location of the registry where keys are retrieved from is:

HKEY_LOCAL_MACHINE\Software\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Object Class\Description

This method comes AS-IS and I have kept everything quite basic, leaving room for any sort of upgrades that may be required in your environment. However, this method does deliver most of the mandatory properties that would be required by the user anyways.

Class clsGetROProperties
   Private arrProperties
   Private sObject
 
   Public Function GetProperties(Object)
      Dim arrObject, ix
 
      Set GetProperties = Nothing
 
      'Retrieve object type / Object Class
      sObject = Object.GetTOProperty("micclass")
 
      'If Object is found in Registry then, add all ROProperties to RecordSet
      If bObjectExistsInReg Then
         Const adVarChar = 200
 
         Set GetProperties = CreateObject("ADODB.RecordSet")
 
         'Add Properties available in the Registry
         For ix = LBound(arrProperties) to UBound(arrProperties)
            Select Case LCase(arrProperties(ix))
               Case ""
               Case Else
                  GetProperties.Fields.Append "" & arrProperties(ix), adVarChar, 2000
            End Select
         Next
 
         'Open the RecordSet Connection for Write Access
         GetProperties.Open : GetProperties.AddNew
 
         'Use .GetROProperty to retrieve and store all values in the RecordSet
         On Error Resume Next
         For ix = 0 to GetProperties.Fields.Count - 1
            GetProperties.Fields(ix).Value = Object.GetROProperty(GetProperties.Fields(ix).Name)
         Next
         On Error Goto 0
 
         GetProperties.Update
      End If
   End Function
 
   Private Function bObjectExistsInReg()
      Dim oRegistry, arrSubKeys, sSubKey
      Const HKEY_LOCAL_MACHINE = &H80000002
 
      bObjectExistsInReg = False
 
      Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\." &_ 
                  "\root\default:StdRegProv")
 
      oRegistry.EnumKey HKEY_LOCAL_MACHINE, GetKeyPath, arrSubKeys
 
      For Each sSubKey In arrSubKeys
         'If Object Class matches one of the Registry Sub-Keys, then, 
         'drill-down to the Description folder of the key
         If UCase(sSubKey) = Trim(UCase(sObject)) Then
            oRegistry.EnumValues HKEY_LOCAL_MACHINE, GetKeyPath & "\" & _
               sSubKey & "\Description\", arrProperties
            bObjectExistsInReg = True
            Exit For
         End If
      Next
 
      Set oRegistry = Nothing
   End Function
 
   Private Property Get GetKeyPath()
      GetKeyPath = "SOFTWARE\MERCURY INTERACTIVE\QuickTest Professional\MicTest\Test Objects"
   End Property
End Class
 
Function GetROProperties(Object)
   Set GetROProperties = New clsGetROProperties
   Set GetROProperties = GetROProperties.GetProperties(Object)
End Function

Download Class clsGetROProperties (With Documentation)

Below are 2 examples how GetROProperties can be used with different objects. I have manually registered the method for the objects.

I would strongly recommend automation developers using this method also read the article RegisterUserFuncX: Register Methods To All QTP Objects Automatically, which can be used to register GetROProperties to all QuickTest Objects.

Example 1:

'RegisterUserFuncX "GetROProperties", "GetROProperties"
RegisterUserFunc "WebEdit", "GetROProperties", "GetROProperties"
 
Set oROProperties = Browser("title:=Google").WebEdit("name:=q").GetROProperties
 
For ix = 0 to oROProperties.Fields.Count - 1
	Print oROProperties(ix).Name & " -> " & oROProperties(ix).Value
Next
 
Set oROProperties = Nothing

Once the snippet above executes, below is what the result would look like in QuickTest Print Log:

GetROProperties Result

GetROProperties Result

Example 2:

'RegisterUserFuncX "GetROProperties", "GetROProperties"
RegisterUserFunc "Link", "GetROProperties", "GetROProperties"
 
Set oROProperties = Browser("title:=Google").Link("innertext:=About Google").GetROProperties
 
For ix = 0 to oROProperties.Fields.Count - 1
	Print oROProperties(ix).Name & " -> " & oROProperties(ix).Value
Next
 
Set oROProperties = Nothing

Once the snippet above executes, below is what the result would look like in QuickTest Print Log:

GetROProperties Result

GetROProperties Result

I hope this article will cover one of the methods that isn’t available with the shipped QuickTest Professional package. Please use the comments section of this article to provide your feedback, offer improvements to this method or report any bugs that you encountered in your environment.

If you have any questions, please ask them in the comments section. If your query is confidential, please use the Contact Form to send me an e-mail instead.

{ 21 comments… read them below or add one }

1 deter December 13, 2009 at 10:10 am

Anshoo,

Great..I think you must have spent hours to get this done..(I had to read about ADODB.Recordset to understand this :))

Well… i have one question..

Cant we add these kind of custom classes..in our project as external libraries..like in java if you want to use struts framework,we just have to add struts library files and can start working.

I just subscribed to your posts..quite interesting..and easy to understand.. :)

Reply

2 Anshoo Arora December 14, 2009 at 2:45 pm

It does take some time depending upon the concept that I am writing about.

Cant we add these kind of custom classes..in our project as external libraries

Sure can!

Thanks for subscribing to Relevant Codes. :)

3 Raja December 14, 2009 at 8:42 am

Hii Anshoo,

Can u please suggest me the regular expression syntax for this —> Officers’ A&B

the problem is it contains a single quote thats y i have to escape it..

Reply

4 Anshoo Arora December 14, 2009 at 2:48 pm

You can try the below:

Officers’ A\&B

You would need to escape the “&” character..

5 Jayachandra January 12, 2010 at 12:20 am

HI Anshoo,

I have a doubt regarding working on ODS file its an OPen Source Excel the question is how to work with ods in QTP instead of Excel?

Thnxs in advance.. Pls Clarify the doubt

Reply

6 randhir kumar February 19, 2010 at 7:55 am

Hi Anshu,

Really, gr8 effort. Heartly congrat for these posts. It really helped me in designing autframework for my project.

Reply

7 Anshoo Arora February 19, 2010 at 9:35 am

I’m happy that the information in this blog helped you, Randhir!

8 Frank April 21, 2010 at 12:27 pm

I tried to use your script.
I am using qtp 10.0

I got the error:
General run error.
Line (4): “Set oROProperties = Browser(“title:=Google”).WebEdit(“name:=q”).GetROProperties

Reply

9 Anshoo Arora April 21, 2010 at 1:27 pm

Hi Frank,

Has the function GetROProperties been registered to all target objects using RegisterUserFunc?

10 Anand Tambey November 25, 2010 at 8:12 am

Hi Anshoo,

Pl. correct me if I am wrong.

1.GetTOProperties returns “Description Properties” from QTP OR.
2.GetROProperties – excellent function – First of all Thanks!!! – This returns run-time properties(useful ones).

However my question is:-
Can we get the properties and values programmatically while mimicking Object Spy completely? (means all properties and values)
Is there something already being done on that front may be using DOM for Web Apps?

Reply

11 Anshoo Arora December 5, 2010 at 9:46 pm

Anand,

I’m not sure if we can get ALL TO properties or mimic what the Object Spy shows. GetROProperties can accomplish that once all the relevant properties are added to the registry, or to an XML file. Without knowing which property a Test Object holds, its not possible as its a custom mechanism. Also, if your AUT is only Web, you can write your own workaround by using arrays/xmls to hold all properties of all Web Test Objects and using those instead.

12 kumar October 10, 2011 at 7:15 am

Hi anshoo,

can your please tell me how to compare the two values which have retrieved from two text boxes using getroproperty.

Reply

13 naunihal singh November 21, 2011 at 1:13 pm

I have been assigned a task in which I need to create an external excel sheet which will have the properties and values of the objects used in object repository. Then I need to call them into my test and create a description of objects in a dynamic way.

Please help/advise how should I do it as its required on urgent basis.
SystemUtil.Run(“C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe”)
Dim Pr
Dim Vl
Dim intcount
Dim globalrows
Datatable.AddSheet (“Properties”)
Datatable.ImportSheet “C:\Properties.xls”,”Sheet1″,”Properties”
globalrows= Datatable.GetSheet(“Properties”).GetRowCount
For intcount=1 to globalrows-1
datatable.SetCurrentRow(intcount)
Pr=datatable.value(“Properties”,”Properties”)
Print (Pr)
Vl=datatable.value(“Values”,”Properties”)
Print (Vl)
Next

Till now I can only check whats coming from the database but cant go further from there.

Your help will really help me.

Reply

14 Frank April 22, 2010 at 1:35 am

Hi Anshoo,
I have copied your scrpit above an used the ReisterUserFunc “WebEdit”, “GetROProperties”, “GetROProperties”.
Do I nedd to add an Entry in the regirsty with HKEY_LOCAL_MACHINE\Software\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Object Class\Description ?

I am a real beginner in using QTP. Thanks for your help.
Frank

Reply

15 Anshoo Arora April 22, 2010 at 10:33 am

Frank,

The following steps should fix this issue:

1. Open QTP
2. Open IE -> Navigate to Google.com
3. Open this file.
4. Copy the code from the above file and paste it in QTP
5. Execute test

It should run fine now :)

Reply

16 always May 11, 2011 at 1:00 pm

Hi,

Good to see the article and hearty congrats for your R &D,
here am putting some concerns/queries on it,which is the part Anand’s question.

shall we use programmatically to get all the properties and their values using DOM?
if it is how can i spy it? is there any way to do it?

how the qtp able to spy the object and getting the properties?

any specific code for it?
Thanks

Reply

17 Anshoo Arora May 19, 2011 at 7:28 pm

@always: The only way you can retrieve these properties is by using the ‘.Object’ or the ‘attribute/propertyName’ extensions. You can retrieve these properties via DP or OR. These properties will be only available for Web objects and you will need to spy at the Native Properties to access them.

Reply

18 Always May 20, 2011 at 12:00 am

Hi,

Can i expect the code for it how can i retrieve all the properties of an object using vbscript(here am not using any toll…like QTP)just running by giving double click on .vbs file.

Reply

19 Anshoo Arora June 24, 2011 at 10:34 am

@always: It will be like this:

Set TextBox = Browser("").WebEdit("")
Set attributes = TextBox.Object.attributes

For Each attribute in attributes
	Print attribute.Name & " -> " & Print attribute.Value
Next

Reply

20 Anonymous June 24, 2011 at 10:32 pm

Hi Anshoo,

Set TextBox = Browser(“”).WebEdit(“”)…………..will it support without QTP tool to set an object here.

Browser & WebEdit ..these are QTP supported objects not vbscript right?

am expecting code without using QTP… running all script just by giving double click on vbs file

Reply

21 Always November 22, 2011 at 7:13 am

Yes..Browser & WebEdit ..these are QTP supported objects not vbscript objects.

i think not possible thru vbscript to get all the properties of an object…but i hope will get attributes

‘ll try and let you know

Reply

Leave a Comment

Previous post:

Next post: