Forum Discussion

geethwind's avatar
geethwind
Contributor
14 years ago

Question on Object Browser



I am migrating my QTP code to Test Complete, i read somehwhere that Object browser of Test complete is similar to Object Repository of QTP. Is that correct? I got stuck in my migration where there is code related to object repository...



my current code function which takes the window title and the object reference to check if it exists in the hiherarchy of the repository as below...can i acheive something similar to it in TC?  - any help or pointers are highly appreciated..



Public function GetRepositoryObj(strWindow, ByRef asrObjName())

 Dim strTmp

 For intObj = 0 To UBound(asrObjName, 1)

  If InStr(astrObjectName(intObj, FLD), ":=") = 0 Then ' Not a dynamic object

   strTmp= GetObjectHierarchy(asrObjName(intObj, FLD), "", False) 'Calls itself recursively to return hierarchy of an object  in  the repository . 

   If strTmp= "" Then

    ReportEvent FAIL, "GetObjectHierarchy", "Object: " & asrObjName(intObj, FLD) & " not found in file: " & strWindow  & ".tsr"

    ExitTest

   End If

   asrObjName(intObj, FLDNAME) = strTemp

   Set asrObjName(intObj, FLD) = Eval(strTemp)

  End If  'Not a dynamic object

 Next

 

End Function



 


  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    That's not exactly a true statement.  The object browser is more an inspector of what exists in the environment where you are creating your tests.  NameMapping, as I understand it, is what you're looking for.
  • Thanks Robert , i tried Name Maping a bit like




    str = NameMapping.Sys.Process("iexplore", 2).Page(https://testlink.).Table(0).Cell(3, 1).innertext



    but i wasn't comfortable how i can pass objects  as a dynamic parameter to it and find the properties of the objects at runtime..is it something possible?



    are there any useful links on how to handle with thse dynamic objects in Test complete?



    Thanks


  • Hi Geeth,



    First of all, let me briefly explain the ways of addressing objects in TestComplete tests.



    As Robert said, the object repository in TestComplete is the Name Mapping project item. It holds the hierarchy of objects for use in your tests and their identification properties. You can address these objects in your tests by their names that are specified in Name Mapping, for example:



    TestComplete automatically adds objects to Name Mapping when you record tests, and you can also add, modify and remove objects in Name Mapping manually.



    However, your tests can just as well use any other objects that are not in Name Mapping (repository). To address these objects, you can use the syntax that directly includes the object's identification properties (this syntax is a kind of analog of QTP's descriptive programming):



    You can see examples of this syntax in the Object Browser (which displays all applications and objects that exist in the system).





    i tried Name Maping a bit like

    str = NameMapping.Sys.Process("iexplore", 2).Page(https://testlink.).Table(0).Cell(3, 1).innertext

    but i wasn't comfortable how i can pass objects as a dynamic parameter to it
    I'm sorry, but I don't quite understand what you mean. Could you please provide some more details on what you're trying to accomplish, maybe your original QTP script that illustrates the point?





    find the properties of the objects at runtime.
    To access an object's property at run time, you can use the dot syntax. For example:

    oldText = Aliases.notepad.wndNotepad.Edit.wText   ' Using object names from Name Mapping (repository)

    oldText = Sys.Process("Notepad").Window("Notepad", "* - Notepad").Window("Edit").wText ' Using an object that isn't in Name Mapping


    If you need to get a list of all properties of an object, you can use the aqObject.GetProperties(object) method (an example is included in the linked article).





    my current code function which takes the window title and the object reference to check if it exists in the hiherarchy of the repository as below...can i acheive something similar to it in TC?
    Not sure if I got it right again, but if you mean that you are given an object reference (e.g. a test variable holding this object), and you need to check if this object is present in TestComplete's Name Mapping ("repository"), you need to examine this object's MappedName property. If it hods a value, this object exists in Name Mapping). If MappedName returns an empty string, the object is not in Name Mapping.

    Please correct me if this is not what you meant.





    are there any useful links on how to handle with thse dynamic objects in Test complete?
    Here's the webinar recording about handling dynamic objects:

    Creating Reliable Tests For Dynamic Objects with Name Mapping

    Hope you'll find it useful!





    If you have any additional questions about migrating your tests to TestComplete, please feel free to start new threads here on the forums, or you can contact our Support Team for personalized support.



    I would also like to note that since QTP and TestComplete are different products and use different concepts, not all of your QTP code may need to be ported to TestComplete, as the corresponding tasks may not be required at all.



    Good luck!