Ask a Question

Use csv/excel file to update Project Suite/Project variables before running test?

SOLVED
shiva_ranabhat
Contributor

Use csv/excel file to update Project Suite/Project variables before running test?

Hi,

 

I was just wondering if there is a way to update project suite/project variables value using data-driven logic?

It would help non-QA staff to just use file to update all variables and run the test in many environments. 

 

Many Thanks,

Shiva

6 REPLIES 6
NisHera
Valued Contributor

You can do something like this...........

 

DDT.ExcelDriver('C:\myVariable.xlsx','sheet1',true);
do {
   if (!Project.Variables.VariableExists("DatabaseName"))
            { Project.Variables.AddVariable("DatabaseName", "String") }
    Project.Variables.DatabaseName = DDT.CurrentDriver.Value('DBname');
    }
while (!(DDT.CurrentDriver.EOF()));
DDT.CloseDriver(DDT.CurrentDriver.Name);

Thanks,

 

Is 'DatabaseName' the name of project suite variable or the variable name column in excel file?

and similarly, is 'DBname' the name of column forvariable values or the variable itself?

 

 

Hi, 

 

what is wrong in my line "ProjectSuite.Variables.varName= varvalue; " line?

It throws a Jscript runtime error: Object doesn't support this property or method.

 

function DDTDriverTest(){
DDT.ExcelDriver('C:\\TestComplete_Parameters\\RedOwl_Parameters.xlsx', "Sheet1", true);

// while there is data
while(!DDT.CurrentDriver.EOF()){

var varName= DDT.CurrentDriver.Value(0);
var varType= DDT.CurrentDriver.Value(1);
var varValue= DDT.CurrentDriver.Value(2);

if(!ProjectSuite.Variables.VariableExists(varName)){
ProjectSuite.Variables.AddVariable(varName,varType);
}

ProjectSuite.Variables.varName= varValue;
DDT.CurrentDriver.Next();
}


// Close driver
DDT.CloseDriver(DDT.CurrentDriver.Name);
}

 

If the value of varName is "foo" and varvalue is "bar"

 

 

var foo = "bar"

 

 

these lines:

  

if(!ProjectSuite.Variables.VariableExists(varName)){
  ProjectSuite.Variables.AddVariable(varName,varType);
}

will create a Project Suite variable called foo, and you can access it using:

 

ProjectSuite.Variables.foo

So your code:

 

ProjectSuite.Variables.varName = varValue;

Tries to set the value of a project suite variable name "varName" instead of "foo". This variable does not exist, and thus gives the error.

 

 

 

 

As a convenience, you can access a variable in the Variables collection by its name.  "varName" is not the name of the variable in the collection.

 

You probably want


ProjectSuite.Variables.VariableByName(varName) = varValue;

-----
Joseph

Cool! This works Cat LOL

 

Thanks Everyone!

cancel
Showing results for 
Search instead for 
Did you mean: