Relevant Codes

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.

{ 11 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. :)

Reply

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..

Reply

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!

Reply

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?

Reply

10 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

11 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

Leave a Comment

Previous post:

Next post: