cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
New Contributor

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

Josh Patterson
1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

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

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
4 REPLIES 4
Community Hero

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

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Community Hero

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

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
New Contributor

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

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?

Josh Patterson
New Contributor

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

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!

Josh Patterson
New Here?
Join us and watch the welcome video:
Watch the New Interview
APITestingMistake#2