
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
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
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.
FaceBook
LinkedIn
Twitter
YouTube
{ 7 comments… read them below or add one }
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.. :)
It does take some time depending upon the concept that I am writing about.
Sure can!
Thanks for subscribing to Relevant Codes. :)
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..
You can try the below:
You would need to escape the “&” character..
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
Hi Anshu,
Really, gr8 effort. Heartly congrat for these posts. It really helped me in designing autframework for my project.
I’m happy that the information in this blog helped you, Randhir!