cancel
Showing results for 
Search instead for 
Did you mean: 

How to access the value of a Project Variable programmatically?

Highlighted
Contributor

How to access the value of a Project Variable programmatically?

Trying to get an idea for how I can interact with Project Variables. Here is a test script I setup:


def TestVars():
  ProjectSuite.Variables.AddVariable("testVar", "Integer")
  ProjectSuite.Variables.VariableByName["testVar"] = 1234
  Log.Error(str(ProjectSuite.Variables.VariableByName("testVar")))

I have a couple of questions.

The above code creates a "Persistent" variable, how do I programmatically create a "Temporary" one?
Secondly, this script fails on the fourth line with the following error.

 

Type Error
`IDispatchIndexedPropertWrapper` object is not callable

 

Any ideas? I want to be able to create and edit and call the value of project variables all within a script.

2 REPLIES 2
Highlighted
Community Hero

Re: How to access the value of a Project Variable programmatically?

When you talk "Persistent" versus "Temporary", are you using the TestComplete monikers where a persistent variable preserves the content of the variable between test runs or is it "Persistent" in that TestComplete creates a variable that is always associated with the project?

 

As for the error... one of the limitations of Python is calling object properties that take a aprameter... you can't do so without using the _getprop_ method (see http://support.smartbear.com/testcomplete/docs/reference/language/python/getprop-method.html).

 

However, couple of things about your code:

 

1) If you want to use a ProjectSuite Variable in your project suite, you don't (and probably shouldn't) add it as part of your automation code.  Consider it the same sort of declaration that you would do if it was a variable in code.  You declare before you use.  So, add your variable to your project suite manually.

2) If you do #1, the you shouldn't have to worry about "VariableByName" at all.  You should be able to get the variable easily just by going 

 

ProjectSuite.Variables.testVar

Robert Martin
[Hall of Fame]
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
Vegas Thrill Rider
Extensions available
Highlighted
Contributor

Re: How to access the value of a Project Variable programmatically?

Alrighty, that was it. Thanks again, again!

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors