Forum Discussion

alinder's avatar
alinder
Contributor
15 years ago

Any workaround to export the text of Aliases and the Name Mapping?

I need to be able to copy/export the names used in the Aliases tree out as text in order to more easily integrate TestComplete with a larger automation framework.



I just need the text of the alias names, preferably with the tree structure intact.



Is there a workaround that has been found to provide this information?



I had found a prior topic (link below) on the matter; is there any update on a feature that provides this?

http://smartbear.com/forums/forum/post/?mode=singleThread&thread=64902e5e-b273-4b52-afc4-6ba5a8983bab



Thanks!

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Okay, here's a rough hack.  However, you should be able to take this and modify it for file output, manipulating what is returned by "MappedName" to get just the last bit of it that you're looking for.



    function ExportAliasTree(AliasObject)

    {

    var ArrayOfChildren, i;

    ArrayOfChildren = AliasObject.FindAllChildren("MappedName", "Aliases.*", 1);

    ArrayOfChildren = (new VBArray(ArrayOfChildren)).toArray();

    if (ArrayOfChildren.length == 0)

    {

    ArrayOfChildren = AliasObject.FindAllChildren("MappedName", "NameMapping.*", 1);

    ArrayOfChildren = (new VBArray(ArrayOfChildren)).toArray();

    }

    for (i=0; i < ArrayOfChildren.length; i++)

    {

    Log.AppendFolder("New Level") 

    Log.Message(ArrayOfChildren.MappedName)

    ExportAliasTree(ArrayOfChildren)

    Log.PopLogFolder()

    }





    }





    function test()

    {

    ExportAliasTree(Aliases);

    }
  • Thank you for the idea, Robert. The approach has some very tempting results.



    The problem is that your approach seems to crawl through the aliases of objects currently displayed in the tested application, not the entire alias tree.



    I did find that you can crudely do the same sort of thing using the GetProperties method and filtering out any property you find that isn't another Alias or Name Mapping item. Code below; I started with something that threw out specific property names, like "Exists","NamedChild","NamedChildCount", or "NodeDescription", but later found that using the below which keys off of ValueType seemed to work for my project.







    Sub GetNextAlias(AliasObject)

        Dim iteratorProperties

        Dim iteratorProp



        Set iteratorProperties = aqObject.GetProperties(AliasObject)

        

        While iteratorProperties.HasNext  

            Set iteratorProp = iteratorProperties.Next

            'ValueType 29 appears to correspond with other objects from the name mapping or alias trees

            If (iteratorProp.ValueType = 29) Then

                    Log.AppendFolder(iteratorProp.Name)

                    GetNextAlias(aqObject.GetPropertyValue(AliasObject,iteratorProp.Name))

                    Log.PopLogFolder

            End If

        Wend

       

    End Sub



    Sub test()

         Log.AppendFolder("Name Mapping")

         Call GetNextAlias(NameMapping.Sys)

         Log.PopLogFolder

         Log.AppendFolder("Aliases")

         Call GetNextAlias(Aliases)

         Log.PopLogFolder

    End Sub

  • Important addendum about the posted code above: This seems like it has to wait for each of the objects to time out, so when using this code, set your Current Project Properties > Playback > Auto-wait timeout value to something unusually small, like 10 ms, if you want this to execute efficiently.