cancel
Showing results for 
Search instead for 
Did you mean: 

Calling objects directly vs returning objects in a function

SOLVED
Contributor

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?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Contributor

Re: Calling objects directly vs returning objects in a function

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. 

View solution in original post

7 REPLIES 7
Community Hero

Re: Calling objects directly vs returning objects in a function

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.


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Occasional Contributor

Re: Calling objects directly vs returning objects in a function

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.

Community Hero

Re: Calling objects directly vs returning objects in a function

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.


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Highlighted
Community Leader

Re: Calling objects directly vs returning objects in a function

Hi 4m4d3u,

 

Few months ago i had the same problem as You. This community helped me a alot and today i can share with you theirs topis and solutions:

 

https://community.smartbear.com/t5/TestComplete-Desktop-Testing/NameMapping-Alias-and-find-function/...

 

https://community.smartbear.com/t5/TestComplete-Desktop-Testing/Project-without-NameMapping/td-p/187...

 

Generaly the good practics to work with nameMapping is to:

1) Do not map everything! this is a optimization trap! Map only what You must have in NameMapping repo and on that objects use .find() function or .WaitAliasChild() function.

 

2) Yes ofc you can store dynamic Aliases with functions on external lib. But be very carefouly with TestComplete Execution process.

 

3) with this example function You can search for object:

 

var alias = () => anchorFind(...);

function anchorFind(alias, propNames, propValues, depth, refresh = true) {

  return alias.Find(propNames, propValues, depth, refresh);
}

Hopes this helps you.

 

Community Manager

Re: Calling objects directly vs returning objects in a function

Community, thanks for your suggestions!

 

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

 

 

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Contributor

Re: Calling objects directly vs returning objects in a function

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. 

View solution in original post

Community Manager

Re: Calling objects directly vs returning objects in a function

It's great to hear that the solution was found!

 

 

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
Top Kudoed Authors