Assigning Variable Values to Remote Machines
Our test structure is one authoring machine writing tests using TestComplete, and TestExecute licenses on the machines that will run the tests. Each machine can install the software to any AppPath, and each machine runs the tests in their own sandbox. Consequently, I need to be able to set the variables for each machine.
I know a better solution is to use XML or some file that lists the variable values for each machine and read those in, but until that framework is implemented, I've been trying to do it this way:
In the Project.Variables collection, there is AppPath, Sandbox, SQLServer, etc. Our machines are named like ABCDE-1234. You can't use dashes in variables, so I just strip those out. So I also have AppPath_ABCDE1234, AppPath_FGHIJ5678, etc.
I have an initialize routine that passes in a variable name, like Sandbox. It then appends _ and hostname to variable name, and uses VariableByName to assign the value. Ideally, this should just need to be run once when a machine connects for the first time, but it's quick enough I just have the routine run at the beginning of our test suite, and just use Project.Variables.Sandbox, for instance, in the tests from then on.
Sorry for the length of this question, but the problem is that the strategy works fine on the authoring machine, but when a remote machine using TestExecute runs the routine, the values are not assigned. I'll post the code below, can anyone tell me why this isn't working?
function AssignVariables(VarName) { var MachineName = aqString.Replace(Sys.HostName, "-", ""); var ConcVar = VarName + "_" + MachineName; if (Project.Variables.VariableByName(VarName)= Project.Variables.VariableByName(ConcVar)) { Log.Message(Project.Variables.VariableByName(VarName) + " now equals " + Project.Variables.VariableByName(VarName + "_" + MachineName) ) } else { Log.Message(VarName + " not assigned.") } }
As I said, when run on the authoring machine, it works fine. When run with TestExecute, it always returns back with VarName not assigned.
I figured out a solution.
You can't assign the value of a persistent variable to a persistent variable, it seems. But you can assign a temporary variable to one.
So simply...
function AssignVariables(VarName) { var MachineName = VarName + "_" + aqString.Replace(Sys.HostName, "-", ""); Project.Variables.VariableByName(VarName) = Project.Variables.VariableByName(MachineName); }
...allows me to populate the Temporary Variables section with Variable_Machine-0123, call the routine as needed, and pass in the variable name to be assigned. Then I can just continue using the original variable in the rest of the tests and scripts.
I know the better way would be to maintain a database or XML file with the machine names and their needed values, but until that is implemented, this will work.
Thank you everyone who responded trying to help. Much appreciated.