Getting Object name from a TestObject in OR - QTP

Each QTP Test Object now support two new properties

® TestObjName: Returns the Name of the object in repository.
® In case the object is not from repository and the application is running then it will return the default name that QTP would have given it if added to OR. This name will be enclosed with square brackets [ ]
® In case the object is not from the repository and the application is not running then the micclass of the object enclosed with square brackets [ ]
® TestObjGenType: Returns the generic type of the object. For example text box, list box, table, text label, etc.

These new properties prove very useful for debugging and logging purposes. The TestObjNameproperty gives use the power to regenerate the whole object statement from an object. We created a functionGetObjectSTR in the "Recovery Scenarios" chapter that allowed converting an object to its string definition. Now we enhance that function to include the TestObjName property in the following code:

'Function to convert a QTP test object into its string
'description.
Public Function
GetObjectSTR(pObject)
Dim sPropsO
ReDimsProps(0)
'Get the name property from TestObjName
sProps(0) = pObject.GetTOProperty("TestObjName")
'Get the type of the objecy
sClass= pObject.GetTOPropertyC'micclass")
'If the name contains [ in the start and ] in the end
'then it is not from object repository
If Left(sProps(0),l)="[" and Right(sProps(0),l)="l" Then
'The object is not from the OR. Continue the normal method
'to get the description of the object
'Get all the test object identification properties
Set oTOProps = pObject.GetTOProperties
iCount = oTOProps.Count- 1
'Loop through and create a array fox string description
Fori = 0 to iCount
sProps(UBound(sProps)) = oTOProps(i).
Name & ":=" &oTOProps(i).Value
ReDimPreserve sProps(UBound(sProps) + 1) Next
Lm Preservei
ReDimPreservesProps(UBound(sProps)-l)
End If
'Create the string object description of current object
sObjectStr = sClass& "(""" &join(sProps,""",""") & """)"
'Check if the object is a top level object
If TypeName(pObject.GetTOProperty("parent")) = "Empty" Then
GetObjectSTR = sObjectStr
"Get the parent object of the current object
Set oParent = pObject.GetTOProperty("parent")
'Recursivly call the function to get the complete description
GetObjectSTR = GetObjectSTR(oParent) & "." &sObjectStr
End If
End Function
'Prints "Dialog("Run").WinEdit("Open:")"
Print GetObjectSTR(Dialog("Run").
WinEdit("Open:"))
'Prints "DialogC"Run").WinEdit("text:=Open:")"
Print GetObjectSTR(Dialog("Run").WinEdit("text: =Open:"))

The TestObjGenType might not be required generally and has no use in the above function.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

QTP Topics