QTP - How to get all Object Indentification Properties?

QTP - How to get all Object Indentification Properties?

There are two ways how to get all properties of an object in QuickTest Professional:
  1. Manually
  2. Programmatically
Use QTP Object Spy to get manually object properties.
I've captured properties of ''Advanced Search" link from Google's page:
So, QTP Object Spy shows these values:
QTP Spy ObjectUsing QTP Object Spy you can get Run-time Object Properties and Test Object Properties.
It's possible to get these properties programatically:
  • The GetTOProperty and GetTOProperties methods enable you to retrieve a specific property value or all the properties and values that QuickTest uses to identify an object.
  • The GetROProperty returns the current value of the test object property from the object in the application.

GetTOProperty differs from the GetROProperty method:
  • GetTOProperty returns the value from the test object's description.
    Test Object Properties are stored in the QTP Object Repository.
  • GetROProperty returns the current property value of the object in the application during the test run.
    QTP reads Run-time Object Properties from actual objects during the runnins can be read and accessed during the run session.

That means that when you work with objects using QTP Descriptive Programming (DP), you will be able to access run-time object properties only (using GetROProperty function). Test object properties (using GetTOProperty function) will not be accessed, because QTP DP doesn't work Object Repository.

There is a problem with Run-time object properties.
In contrast to GetTOProperties (which returns the collection of all properties and values used to identify the test object), GetROProperties function does NOT exist!
Once again - GetROProperties function does NOT exist!


Well, how to get all Object Indentification Properties of an object?
Answer:
We can read them from Windows Registry.

The following registry key contains properties of a given test object:
HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\_Test_Object_\Properties

For example, I've opened:
HKEY_LOCAL_MACHINE\SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Link\Properties and I've got properties of Link object:

Please note that you can find the same Link Identification Properties in QuickTest Professional Help:
Link Indentification Properties from QuickTest Professional Help
QTP Object Identification Properties can be used:
  • in the object repository description
  • in programmatic descriptions
  • in checkpoint and output value steps
  • and as argument values for the GetTOProperty and GetROProperty methods

So we have to read all Identification Properties from the registry.
This QTP code reads Link Identification Properties:
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

sKeyPath = "SOFTWARE\Mercury Interactive\QuickTest Professional\MicTest\Test Objects\Link\Properties"
oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyPath, arrNames


As a result, arrNames array contains all names of properties.
To prove my words I use this QTP script:
sNames = "Identfication Properties:" & vbNewLine

For
i = 0 to UBound(arrNames)
    sNames = sNames & arrNames(i) & vbNewLine
Next

MsgBox
sNames
The result is:
Compare these Link Identification Properties with properties from the registry. They are the same!

So, we can read names of properties.

Next step is to read their values. It can be archived using GetTOProperty or GetROProperty.
Also, I'm going to show how GetTOProperty and GetROProperty work for Test Object (located in QTP Object Repository) and Run-time Object (actual object, created during the run session).

  1. Properties of Test Object
    QTP script is:
    ' Link("Advanced Search") is an object from QTP Object Repository
    Set TestLink = Browser("Google").Page("Google").Link("Advanced Search")

    sNamesTO = "GetTOProperty for Test Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine
    sNamesRO = "GetROProperty for Test Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine

    For i = 0 to UBound(arrNames)
        sNamesTO = sNamesTO & arrNames(i) & ": " & TestLink.GetTOProperty(arrNames(i)) & vbNewLine
        sNamesRO = sNamesRO & arrNames(i) & ": " & TestLink.GetROProperty(arrNames(i)) & vbNewLine
    Next

    MsgBox sNamesTO
    MsgBox sNamesRO
    • Test Object Properties of Test Object
      Test Object Properties of Test Object and their values are:
      Test Object Properties for Test Object
    • Run-time Object Properties of Test Object
      Run-time Object Properties of Test Object and their values are:
      Run-time Object Properties for Test Object

  2. Properties of Run-time Object
    QTP script is:
    ' Link("text:=Advanced Search") is a dynamic run-time object
    Set TestLink = Browser("Google").Page("Google").Link("text:=Advanced Search")

    sNamesTO = "GetTOProperty for Run-time Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine
    sNamesRO = "GetROProperty for Run-time Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine

    For i = 0 to UBound(arrNames)
        sNamesTO = sNamesTO & arrNames(i) & ": " & TestLink.GetTOProperty(arrNames(i)) & vbNewLine
        sNamesRO = sNamesRO & arrNames(i) & ": " & TestLink.GetROProperty(arrNames(i)) & vbNewLine
    Next

    MsgBox sNamesTO
    MsgBox sNamesRO
    • Test Object Properties of Run-time Object
      Test Object Properties of Run-time Object and their values are:
      Test Object Properties and their values of Run-time ObjectWhy almost all properties are empty?

      As I said, GetTOProperty function gets values from Test Object, which is stored in QTP Object Repository. Since Run-time Object is a dynamic object, it's not stored in QTP Object Repository. That's why GetTOProperty function cannot read object's properties.

      Look at the above screenshot again. The only one property ('text') contains its value ('Advanced Search'). We used this property to create description for our link:
      Set TestLink = Browser("Google").Page("Google").Link("text:=Advanced Search")
      That's why this Run-time Object contains the only property.

    • Run-time Object Properties of Run-time Object
      Run-time Object Properties of Run-time Object and their values are:
      Run-time Object Properties of Run-time ObjectAs you can see, we got the same Run-time Object Properties both for Test Object and for Run-time Object. I can explain it.
      During the run session, QTP creates a Run-time copy of Test Object. That's why Run-time Object Properties were the same for Test Object and Run-time Object.

    Note: You can download final QTP script here.
--
Dmitry Motevich


Related articles:


How about automatic receiving such QTP tutorials?
Just subscribe to this blog RSS feed or by Email. (How to subscribe? VIDEO guide)




Do you like this QTP visual tutorial? Feel free to place it on your site or blog.


9 comments:

Anonymous said...

Dmitry,

Very good article.
However, I believe that you are confused about object Run-Time properties. There are native object properties and some of them are mapped to QTP properties.

Igor

Dmitry Motevich said...

@Anonymous (Igor),
Yes, I agree that "There are native object properties and some of them are mapped to QTP properties.".
And what? What's wrong with Run-time properties?

Anonymous said...

Dmitry,

Your last snapshot titled "Run-time Object Properties of Run-time Object", but they are Run-Time properties of Test object. Run-Time object properties can be accessed via .Object method and has properties like: accessKey, host, hreflang, etc. for Link object.

Igor

Anonymous said...

I want to use WScript object.



I am getting error (erro Object required: 'WScript' Line (2): "Set WshShell = WScript.CreateObject("WScript.Shell")) at the below line of code



Set WshShell = WScript.CreateObject("WScript.Shell")



Do I need to install anything to create and use WScript object.

pep said...

Hello when i run this code it gives me error Like "Type Mismatch "Ubound"'

can u pls help why it throw such error and in what way i can solve this and move further

Dmitry Motevich said...

@Anonymous/Igor (December 9, 2008),
Igor, Test Object does not have its run-time properties. Instead of it, test object reads them from Run-Time Object during the run session.

Yes, you can get native run-time properties of Run-Time Object using 'Object' property.
To summarize, I can say that Run-Time of Test Object is a subset of native run-time properties of Run-Time Object.

So, the article provides correct info.

Dmitry Motevich said...

@pep (January 23, 2009),
Since you didn't provide enough info about your issue, I cannot help you.
You didn't even specify which line causes the error.

Dave said...

After recording the script for google page...

and copied this code into the script and ran it...

'******************************************

' Link("text:=Advanced Search") is a dynamic run-time object
Set TestLink = Browser("Google").Page("Google").Link("text:=Advanced Search")

sNamesTO = "GetTOProperty for Run-time Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine
sNamesRO = "GetROProperty for Run-time Object" & vbNewLine & "Identfication Properties: Values" & vbNewLine

For i = 0 to UBound(arrNames)
sNamesTO = sNamesTO & arrNames(i) & ": " & TestLink.GetTOProperty(arrNames(i)) & vbNewLine
sNamesRO = sNamesRO & arrNames(i) & ": " & TestLink.GetROProperty(arrNames(i)) & vbNewLine
Next

MsgBox sNamesTO
MsgBox sNamesRO

' ******************************************************

this error msg occured:

Type mismatch: 'UBound'

Line (8): "For i = 0 to UBound(arrNames)".


Where is the (arrNames) coming from?

in the script nothing is being assigned to arrNames?

Please help!

revaraghavan said...

hi,
I have a problem with importsheet method...my sheet is not getting imported even when the syntax and naming is corret...need suggesstions on how to proceed..pls help