Forum Discussion

Amytav's avatar
Amytav
Occasional Contributor
5 years ago

Keyword Test - Passing Name mapping array of objects

Hi Everyone,

We are trying to create a reusable function with the objective of  the function taking dynamic number of Namemapping objects passed as parameter in a keyword test. Unfortunately, keyword test do not seem to support such an idea as far as we could observe. Any feedback on how to successfully pass an array of name mapping objects from keyword tests will be much appreciated.

 

 

Example function to be fed with name mapping objects:

function GenerateShareholderListReportName(nameMappingArrayOfObjects){

var reportNameArray = new Array();

for (i=0; i<nameMappingArrayOfObjects.length; i++){

reportNameArray.push(nameMappingArrayOfObjects[i])

}

var reportName = reportNameArray.join("; ");

return reportName;

}

 

  • Hi Sonya,

    We are not passing any aliased or namemapped object from keyword test as did not find solution for that.

    But will try to minimize usage of xpath as per advice given.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    I am not sure that I've got the whole idea...

    You must use code in order to create an array of objects. Then you should be able to pass this array to keyword test as a parameter. (Never tried this, thus this should be checked.)

    While you can create an array of NameMapped (better - Aliased) objects and pass it to some other function, this is usually not the best idea in TestComplete's world. The case is that Aliases object in TestComplete caches actual objects and tries to reuse them. The problem is that if aliased object is recreated in the tested application (e.g. table with data has beed recreated as a result of some ajax request and page script), its cached copy becomes invalid but is not destroyed and can be refreshed from test code. So, the longer test code passes Aliased object through function calls, the higher the chances (especially, for web applications) that the object will become invalid. In order to prevent false negative failures, test code should always consider whether or not the given object must or may not be valid and proceed appropriately.

    Obvoiusly, for performance considerations your test code should search for tested objects as little as possible and use references to the found ones as long as possible. But on the other hand you must consider the life time of this or that tested object in the tested application and search for the new or recreated object when needed.

     

    > reportNameArray.push(nameMappingArrayOfObjects[i])

    > var reportName = reportNameArray.join("; ");

    While technically it might be possible to join an array of complex tested objects into a string... What output are you expecting for?

     

    • Amytav's avatar
      Amytav
      Occasional Contributor

      Hi Alex,

      Thanks for your reply. We are looking to get the ContentText of the objects (Not mentioned in the function code snippet). At the moment, we are passing Xpath of the objects and internally getting the content text of these objects after which converting to a string format with delimiter ";" as per the functionality check required for our application.

       

      Any other workarounds possible excluding name mapping as you've mentioned the pitfalls that could arise?

      The client wants us to only use name mapping for all check but we think xpath is an easier alternative :-)

      • Marsha_R's avatar
        Marsha_R
        Moderator

        I think your client and AlexKaras are correct.  NameMapping and Aliases are much easier to use.

         

        Once you have the context text, why are you converting it to a string?   mycontexttext + ";" will get you the string you want.