Forum Discussion

4m4d3u5's avatar
4m4d3u5
Contributor
5 years ago
Solved

Calling objects directly vs returning objects in a function

Another person and I were hired to do scripting in test complete. How they have it set up is that all the objects are being returned in libraries as function calls example:

 

function getObject(){

       return nameMapping

}

 

So we create a project of just libraries and we import those libraries into our projects. And when we want to call those objects in a script we say:

 

libraryName.getObject()

 

Should we be using objects this way or should we just be calling them directly from the mapping? This way gives us better object manipulation if the object is a string we can just put a cast in our function to always have a object return a certin data type. Or we can maniplulate the object how we want. What is the best way to go about this?

 

 

 

  • 4m4d3u5's avatar
    4m4d3u5
    5 years ago

    We took a hybrid solution, we incorporated the find and find child functions into our libraries. We still see there is benifit from creating libraries with funcitons returning our objects. 

7 Replies

  • cunderw's avatar
    cunderw
    Community Hero

    That seems like a lot of overheard in my opinion and is definitely not needed.

     

    If you have a good mapping and have setup human readable Aliases, I don't see how that way could ever be usefule IMO.

    • RileyMartinez's avatar
      RileyMartinez
      Occasional Contributor

      What happens if the alias of the namemapping changes? All scripts that use that alias namemapping will need to be updated to the new alias name.

       

      Wouldn't returning the namemapped object from a function be more robust if the namemapping changes? Just edit the function in one spot, and all of the scripts are working again.

      • cunderw's avatar
        cunderw
        Community Hero

        If your Aliases are changing that much then you aren't really using mapping properly. Your namemapping file should be designed in such a way that your Aliases are only the main parts of the UI you interact with and shortened as mush as possible. The mapping is where the shuffling should be occuring, not the Aliases.

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Community, thanks for your suggestions!

     

    4m4d3u5, which solution did you decide to use? Please share it with us.

     

     

    • 4m4d3u5's avatar
      4m4d3u5
      Contributor

      We took a hybrid solution, we incorporated the find and find child functions into our libraries. We still see there is benifit from creating libraries with funcitons returning our objects.