Persisting ProjectSuite Variables
Hi,
I have structured my TestComplete Project Suite in such a way that each functional area of the UI has a separate Project. My requirements are that:
1) Some of my tests rely on data created in earlier tests. I have overcome this by saving IDs generated into ProjectSuite variables that can then be used by other Projects. When I run a keyword test in Project (1) then it is saving the variable value correctly but if I then attempt to run a keyword test in Project (2) that uses this variable then it is using the default value rather than the one that it has just been assigned. Am I misunderstanding the concept of how this works or is there a way to make the variable value persist between test runs until it gets reassigned?
2) I would like to paramemterise database calls so that I can easily change the server/database name. To do this I have created a new ProjectSuite variable with a default value that I will update as required. However, when I update the database connection strings to use these new varaibles they are not using the default values. If I assign the ProjectSuite variable a value in the script then this is working correctly but it does not seem to be using the default value that I have setup - is this possible?
Cmd.ConnectionString = "Provider=SQLOLEDB;Data Source=" + ProjectSuite.Variables.DatabaseServer + ";Initial Catalog=" + ProjectSuite.Variables.Database + ";Integrated Security=SSPI;"
Persistent variables have a "Default Value" and a "Local Value". For that matter, temporary variables also have a "Default Value" and a "Local Value" (but the local value is not shown). Your test always works with the local value, however the local value is initialized differently.
For temporary variables, the local value is initialized from the default value when the test starts on the machine. You can watch the local value by adding the temporary variable to the Watch List during the test run.
For persistent variables, the local value is initialized from the default value when the *project suite* is initialized on the machine. When you create a persistent variable manually (by using the GUI to add it to the Project Suite or Project), you are assigning a default value and a local value. When you create a persistent variable programmatically, you are assigning a default value (!) to the default value and local value (Working With Project and Project Suite Variables in Scripts). The default value for persistent variables is somewhat pointless on the local machine because once you've created the persistent variable, you've also assigned the local value. *However*, if you share the project suite on another machine, then the other machine will have its own copy of the persistent variables and their local values will be initialized from the default values.
Kinda confusing. Took me a while to get it straight (and I'm still not sure I've got it all...)
Getting back to your problem:
1) Sounds like you are using a temporary Project Suite variable rather than a persistent variable. See Project And Project Suite Variables - Overview.
2) Here, it sounds like you're using persistent variables and expecting that the default value will re-initialize the local value. Not so. Once the local value of a variable has been set, the default value is no longer of use. (and you've set the local value simply by having created the variable)