Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the logical name of a test object (that exists in the associated shared OR)?

Tags:

qtp

hp-uft

Let´s say I pass a Browser("MyBrowser").Page("MyPage").WebCheckBox("MyBox") to a function:

MyFunction (Browser("MyBrowser").Page("MyPage").WebCheckBox("MyBox"))

Later, the function wants to log the logical name of the received test object (which in this case, of course, is "MyBox").

How could it do that?

The "name" test object property returns the name that is built if you re-add the test object. There is no (documented) test object property for the logical name. The runtime object properties can´t possibly contain the name since it is not a name from the AUT GUI.

So I think the test object does not know its name. Only the repository "knows" under which name the test object is stored there.

So I will have to inspect the repository itself, not the test object.

The ObjectRepositoryUtil API allows me (via GetChildren, or other methods) to find the test object in the repository´s test object collection, and use the GetLogicalName method to get its name. Fine.

But the only way to get that to work is to obtain a reference to a repository by loading it. I get the impression this API is designed to manipulate (or analyze) repos from outside of QTP, not from within a test run. I do not want to re-load the repository. I want to look up the test object in one of the already-loaded repositories.

The RepositoriesCollection API can tell me which are loaded (by their name and path), but it does not provide a means of obtaining a reference to the object instance that represents one of those repositories.

So how can I obtain a reference to an already-loaded repository, so I can use GetLogicalName?

Or generally asking: Given a reference to a "normal" test object contained in the current action´s shared repository, how can I find out its logical name programmatically?

If there is some ultra-wise QTP wizard a la Motti who knows this can not be done, I´d really appreciate an answer from him even if it reads "it cannot be done" if this is true.

like image 864
TheBlastOne Avatar asked Aug 28 '13 13:08

TheBlastOne


People also ask

Does UFT supports identifying objects based on its location relative to another object?

In this stage, UFT checks if Visual Relation Identifiers (VRI) are defined. VRI is a set of definitions that enable you to identify the object in the application according to the relative location of its neighboring objects.

How does QTP identify objects in the application?

QTP performs the operation only after identifying the object uniquely. In order to identify the object uniquely it uses property values of the respective object which will be stored in the Object Repository. Note: To view the property values of the object, QTP uses Object Spy. Object Spy is a tool available in QTP.

Is not used for adding the test object to the shared object repository?

Step to add test object to the shared object repository - Add object: - add all test objects of a certain type. Therefore Active screen is not a step use for adding a test object.


2 Answers

You want the "TestObjName" property:

function GetRepoName(obj)
    GetRepoName = obj.GetTOProperty("TestObjName")
end function

Usage:

logicalName = GetRepoName(Browser("MyBrowser").Page("MyPage").WebCheckBox("MyBox"))
'logicalName now equals "MyBox"

Should you feel the need to reconstruct the entire object chain as a string, you can use the following method "GetFullQtpName" (which also requires GetRepoName plus the 2 extra methods below):

function GetFullQtpName(obj)
    dim fullQtpName : fullQtpName = MakeQtpName(obj)
    dim objCurrent : set objCurrent = obj

    do while not IsEmpty(objCurrent.GetTOProperty("parent"))
        set objCurrent = objCurrent.GetTOProperty("parent")
        fullQtpName = MakeQtpName(objCurrent) & "." & fullQtpName
    loop

    GetFullQtpName = fullQtpName
end function

function MakeQtpName(obj)
    MakeQtpName = GetClassName(obj) & "(""" & GetRepoName(obj) & """)"
end function

function GetClassName(obj)
    GetClassName = obj.GetTOProperty("class Name")
end function

Usage:

fullQtpName = GetFullQtpName(Browser("MyBrowser").Page("MyPage").WebCheckBox("MyBox"))
'fullQtpName now equals "Browser("MyBrowser").Page("MyPage").WebCheckBox("MyBox")"
like image 136
Xiaofu Avatar answered Sep 29 '22 23:09

Xiaofu


For convenience, I joined all of these separate functions into a single function (GetFullORName), and it works GREAT! I use it to give better Reporter.Event info in my custom functions...

Function GetFullORName (obj)
    Dim fullUFTName : fullUFTName = obj.GetTOProperty("class name") & "(""" & obj.GetTOProperty("TestObjName") & """)"
    Dim objCurrent : Set objCurrent = obj
    Do While Not IsEmpty(objCurrent.GetTOProperty("parent"))
        Set objCurrent = objCurrent.GetTOProperty("parent")
        fullUFTName = objCurrent.GetTOProperty("class name") & "(""" & objCurrent.GetTOProperty("TestObjName") & """)" & "." & fullUFTName
    Loop
    GetFullORName = fullUFTName
End Function


Public Function CheckObjExist (obj)
    If obj.Exist Then
        Reporter.ReportEvent micPass, "CheckObjExist [" & obj.GetTOProperty("TestObjName") & "]", "Object = [ " & GetFullORName(obj) & " ]" & Chr(13) & "Object exists"
        CheckObjExist = True
    Else
        Reporter.ReportEvent micFail, "CheckObjExist [" & obj.GetTOProperty("TestObjName") & "]", "Object = [ " & GetFullORName(obj) & " ]" & Chr(13) & "Object does NOT exist"
        CheckObjExist = False
    End If
End Function
like image 26
Scott Zillitto Avatar answered Sep 30 '22 01:09

Scott Zillitto