Ask a Question

Assigning Variable Values to Remote Machines

SOLVED
kirk_bottomley
Contributor

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. 

17 REPLIES 17
ashokkumareds
Contributor

Hi,

I believe the culprit is the "If" statement.

It has 2 problems.

1. you have used "=" operator instead of "==". Is this by accident??

2. Use a aqString.Compare instead.

 

please post the updates. thank you,

 

 

Thank you.
Ashok [[ -- If any answers helps you please give Kudos or Accept it as a solution to help others -- ]]
chrisb
Regular Contributor

Use triple equals to avoid type coercion. Also, you say it runs fine on one machine but not remote machines. Did you put a breakpoint in your script and check the values of the variables to compare and see what you are getting?

 

What happens when the script fails on the remote machines, do you get the log message in your else statement?

 

I am also wondering if your Sys.HostName is what you expect on the remote machines?

 

 

function assignVariables(varName)
{
var machineName = aqString.Replace(Sys.HostName, "-", "");
var concVar = varName + "_" + machineName;
if (Project.Variables.VariableByName(varName)=== concVar){
    Log.Message(Project.Variables.VariableByName(varNa​me) + " now equals " + Project.Variables.VariableByName(varName + "_" + machineName) )
  }else
  { Log.Message(VarName + " not assigned.")
  }
}

chrisb
Regular Contributor

Use triple equals to avoid type coercion.

chrisb
Regular Contributor

I am wondering if you have the project variable concVar saved to the variables object on your 'authoring' machine and it does not exist on the remote machine where you have the issue. Why not just compare varName against the conVar variable whose value you just create on the fly?...

 

function assignVariables(varName)
{
var machineName = aqString.Replace(Sys.HostName, "-", "");
var concVar = varName + "_" + machineName;
if (Project.Variables.VariableByName(varName) === conVar)
  { Log.Message(Project.Variables.VariableByName(varNa​me) + " now equals " + Project.Variables.VariableByName(varName + "_" + machineName) )
  }else{
    Log.Message(varName + " not assigned.")
  }
}

chrisb
Regular Contributor

Run Test Complete on your remote machine and put some breakpoints in your test and verify that your two project variables exist when running the test on your remote machine. If you cant run TC on the rmeote machine then add some logging to write the two project variables in your test to the test logs to verify they actually exists. Perhaps you created them on your 'authoring' machine and they dont exist on the remote.

chrisb
Regular Contributor

Put some logging in your test to write the machine name and VarName to your test log to see what they are when test execute runs it.Perhaps also do the same for your project variables.
Also, I think you could simplify the way you do your logging message in the if statement. You've already verified that it matches the project variable so just write the project variable to the log rather than build the string again.


function AssignVariables(VarName)
{
var MachineName = aqString.Replace(Sys.HostName, "-", "");
Log.message(MachineName);

var ConcVar = VarName + "_" + MachineName;
Log.message(ConcVar);

if (Project.Variables.VariableByName(VarName) === Project.Variables.VariableByName(ConcVar))
{
Log.Message(Project.Variables.VariableByName(VarName) + " now equals " + Project.Variables.VariableByName(ConcVar) )
}
else
{
Log.Message(VarName + " not assigned.")
}
}

"you have used "=" operator instead of "==". Is this by accident??"

 

Not an accident, that's on purpose. Most operations return a 1 if they're successful, so writing it that way allows an error catch. It performs the operation as desired, and if true logs a success, but if false logs a failure.

 

Thanks for the feedback! 

 

"Use triple equals to avoid type coercion."

 

Thank you for the feedback! I'm assigning variables in the function, though, not comparing them. I will probably add some comparisons when I write more logging. Thanks for the '= = =' suggestion for extra type comparisons. That might come in handy.

"Run Test Complete on your remote machine"

 

I wish I could, that would solve the issue altogether. I could run the automation once on each new machine that will run the tests and use the GUI to assign the local values of the needed variables.

Unfortunately, we only have the one node-locked license for TC and several licenses for TE for the remote machines, so I have to work out "creative methods" for getting the local values for the project variables right.

cancel
Showing results for 
Search instead for 
Did you mean: