cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Default Variable Value from code

mfoster711
Frequent Contributor

Setting Default Variable Value from code

Is there any way to set the default variable value for a persistent ProjectSuite, Project or Network variable from a script? 



Seems like the only option from code is setting the local value. I want to be able to set a variable value from within a script and then be able to open my project on a second PC and have that value already set.
3 REPLIES 3
tristaanogre
Community Hero

RE: Setting Default Variable Value from code

I don't think the Local value (which is what you're looking for) is something that is automatically populated upon copying a project to another drive location.  At least, it only gets populated with what you mark as the "Default" value.



What I've done in the past is use the Storages object (click here) and used the INI methods.  Every machine, then, that I have configured to run a project has an INI file that is local to that machine so that.  Then, at the beginning of the project, before I run any tests, I read the INI file and populate the local variable values with the values in the INI.



Hope this helps!

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
mfoster711
Frequent Contributor

RE: Setting Default Variable Value from code

I am confused by your reply.  I am not copying a project. I have a project saved on my network drive. I open the networked project in Shared mode on various PCs. Each PC opens the same project.



I have a form that I use to manage some test variables specific to the applications I am testing. I want to set the variables from PC1 and save to a variable. Then, if I go to PC2 and open the project, I want the variable value I set on PC1 to be there.
tristaanogre
Community Hero

RE: Setting Default Variable Value from code

Ah, gotcha.  Sorry, I misunderstood your situation.



I think the problem is essentially going to be the same.  The value of a persistant variable is, I believe, localized.  I don't think it is something that transfers from one PC to another.  What you set the value to on PC1 remains with PC1 and does not transfer to PC2.  The only way I know of (and I could easily be wrong here) to get a value set on PC1 and have it utilized by PC2 is to externalize the value outside of the actual TestComplete project.  Again, using the Storages object (link in previous post) either as an INI file or as an XML where you can read and write values from the file, would be your best way, I believe, to do what you're asking.

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
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors