There are two ways how to get all properties of an object in QuickTest Professional:
Manually
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:
Using 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:
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) andRun-time Object (actual object, created during the run session).
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:
Run-time Object Properties of Test ObjectRun-time Object Properties of Test Object and their values are:
Properties of Run-time ObjectQTP 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 ObjectTest Object Properties of Run-time Object and their values are:
Why 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 ObjectRun-time Object Properties of Run-time Object and their values are:
As 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.
No comments:
Post a Comment