How can I get the logical name of a test object (which exists in a linked common OR)?

Let's say I pass the Browser("MyBrowser").Page("MyPage").WebCheckBox("MyBox") functions:

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

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

How can I do that?

The test object's name property returns the name that is created if you re-add the test object. There is no (documented) property of a test object for a logical name. The properties of the runtime object cannot contain a name because 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 what name the test object is stored.

Therefore, I will need to inspect the repository itself, and not the test object.

The ObjectRepositoryUtil API allows me (via GetChildren or other methods) to find a test object in the collection of test repository objects and use the GetLogicalName method to get my name. Good.

But the only way to make it work is to get a link to the repository by downloading it. I get the impression that this API is designed to manipulate (or analyze) repositories outside of QTP, and not from a test run. I do not want to reload the repository. I want to see a test object in one of the already downloaded repositories.

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

So, how can I get a link to an already downloaded repository, so I can use GetLogicalName ?

Or, as a rule, the task: given the link to the "normal" test object contained in the general repository of the current action, how can I find out its logical name programmatically?

If there is some superintelligent QTP master, and la Motti, who knows that this cannot be done, I really appreciate the answer from him, even if he reads “this is impossible”, if it is true.

+6
source share
4 answers

You want the TestObjName property:

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

Using:

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

If you feel the need to restore an entire chain of objects as a string, you can use the following GetFullQtpName method (which also requires GetRepoName plus two additional 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 

Using:

 fullQtpName = GetFullQtpName(Browser("MyBrowser").Page("MyPage").WebCheckBox("MyBox")) 'fullQtpName now equals "Browser("MyBrowser").Page("MyPage").WebCheckBox("MyBox")" 
+8
source

For convenience, I connected all these separate functions to one function (GetFullORName), and it works GREAT! I use it to provide the best Reporter.Event information 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 
+1
source

The only workaround that I just came up with has many obvious flaws, including its incompleteness, and looks like this:

 Function GetLogicalName (ByVal TestObject) Dim NameWithType: NameWithType=TestObject.ToString Dim TypeProp: TypeProp=TestObject.GetTOProperty ("micclass") Dim Suffix Select Case TypeProp Case "Page" Suffix=" web page" Case "Browser" Suffix=" browser" Case "JavaApplet" Suffix=" applet" Case "JavaButton" Suffix=" button" Case "WebCheckBox" Suffix=" check box" Case "WebEdit" Suffix=" edit box" Case "WebElement" Suffix=" object" Case "WebFile" Suffix=" edit box" Case "WebTable" Suffix=" table" Case "JavaObject" Suffix=" object" Case else MsgBox "Unknown micclass '" & TypeProp & "'" ExitTest End Select GetLogicalName=Left (NameWithType,Len (NameWithType)-Len (Suffix)) End Function 
0
source

A logical name can be obtained with a simple line of code, and not so many lines:

In your case:

The function should return the logical name of the object from the argument

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

 Function MyFunction(obj) MyFunction= obj.ToString() 'This is an inbuilt method of object in QTP End Function 

Let me know if this helps.

0
source

Source: https://habr.com/ru/post/952660/


All Articles