Forum Discussion

shiva_ranabhat's avatar
shiva_ranabhat
Contributor
9 years ago
Solved

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

  • 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);

  • joseph_michaud's avatar
    joseph_michaud
    9 years ago

    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;

6 Replies

  • NisHera's avatar
    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);

    • shiva_ranabhat's avatar
      shiva_ranabhat
      Contributor

      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?

       

       

    • shiva_ranabhat's avatar
      shiva_ranabhat
      Contributor

      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);
      }

       

      • joseph_michaud's avatar
        joseph_michaud
        Moderator

        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;