Forum Discussion

jpatterson's avatar
jpatterson
New Contributor
6 years ago

What is the best practice for project wide counter in TestComplete?

Hello,

 

I am fairly new to TestComplete and am looking for ways to impliment a project wide counter using JavaScript.  I can think of two ways in which the variable will not lose scope: Global Variables and nested scripts.  Neither of these options look very efficent (Global Variables don't have a defined "set" method for modifing their values other then $set that I can find in the documentaion).  Is there another/better way that I have not run across?

 

Thanks in advance,

Josh

  • tristaanogre's avatar
    tristaanogre
    6 years ago

    You could also use the mechanic in JavaScript of module.export and requires to add variables and objects to other code units.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    There are project Variables (acccessed by Project.Variables.<variable name>) that are global throughout the specific project.  You could also create a variable on the Project Suite level (ProjectSuite.Variables.<variable name>) that would span all projects within the project suite.  Either is a built in way of having a global variable that is not language specific nor do you need to worry about any include statements or nested code.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      You could also use the mechanic in JavaScript of module.export and requires to add variables and objects to other code units.

      • jpatterson's avatar
        jpatterson
        New Contributor

        I was overthinking the solution.  Using shared exported variables I was able to incriment the shared variable in a local script (which changed the variable value at the project level), which is exactly what i was looking for.  Thanks again!

    • jpatterson's avatar
      jpatterson
      New Contributor

      Thank you for your quick response!  I was looking into those, but I didn't see a good built in way to incriment a global variable.  The best approch that I could come up with was creating a global variable that is incrimented through a shared javascript closure function.  This seems to be a bit extravaigent for a simple global counter.  The global variables have plenty of "get" methods but no clear "set" methods.  Am I overlooking something?