Forum Discussion
An alternative to the import/export functionality of JavaScript is, in your unit in which you want to use the constants, add
//USEUNIT <unitname>
at the top of the unit. This will bring over everything... otherwise, yes... you would need to declare all the constants.
An additional alternative would be, rather than having the constants sitting out there in the open, put them in some sort of object. Something like
var myContants = {colSelect_RSR: 0, colSts_RSR: 10 ... etc...}
Then, just export myConstants and reference the different properties.
A slightly more advanced alternative would be to wrap all your constants in read-only properties of a Script Extension RunTime object.
Hi Robert,
Thank you for your quick answer. I am very new in Test Complete so this definitely helps me. Anyway, so when I use //UseUnit, I don't need to export/import them? Can I use //USEUNIT in javascript?
Thanks,
- tristaanogre9 years agoEsteemed Contributor
Correct, with //USEUNIT you don't need to the export/import stuff and it is available in JavaScript in TestComplete
- CSL9 years agoContributor
Awesome, but I'm wondering what is the purpose of import/export then. Why does TC even have that? just curious.
Thanks, I'll give //USEUNIT a try.
- tristaanogre9 years agoEsteemed Contributor
Import/export is part of JavaScript, usuable outside of the TestComplete environment. so, it's not a matter of it being something that TestComplete does but just native to JavaScript.
TestComplete includes the //USEUNIT support for those situations where someone has converted a JScript project to JavaScript so that little editing needs to be done. THAT is part of TestComplete.
As mentioned, you CAN use modules.export to export an object... There's a few different ways you can do that, but, in essence, anything you want available in other units needs to be exported somehow if you're going to go that route.
See https://support.smartbear.com/testcomplete/docs/scripting/calling-routines/declared-in-another-unit/javascript.html