Forum Discussion

rmnrdi's avatar
rmnrdi
Contributor
6 years ago

Setting TC wide variables that are globally available for all projects

Is there a way to set global variables for all of TC? Script Extension properties maybe?

 

The applications we're testing have paths to various folders. These folders will need to be accessed from many tests.

BUT the paths to those folders may change.

ex.

Path = "C:\folder\folder\Outgoing";

Path = "\\192.168.0.1\Outgoing"

Path = "C:folder\folder\differentfoldername\Outgoing"

 

This base directory (everything leading up to \Outgoing) can be found in the registry. No problem, got that handled.

 

Here's the code I'm currently using:

function SetInnovationsVariables()
{
    AssignPathVariable("ArchivePath","String","Archive");
    AssignPathVariable("OutgoingPath","String","Outgoing");
      
    Log.Message(ProjectSuite.Variables.OutgoingPath); 
}


function AssignPathVariable(variableName, variableType, folderName)
{
    if(!ProjectSuite.Variables.VariableExists(variableName))
      ProjectSuite.Variables.AddVariable(variableName,variableType);
    var path = GetCurrentDBPath() + "\\" + folderName + "\\";
    
    return path;    
}

Function AssignPathPariables will get the current db base path and stick the folder name I want on the end. 

When I calll that function from SetInnovationsVariables, I would expect it to set the variable, but it doesn't.

 

It logs the correct path, but it's not available for any other project.

 

The problem is, setting these things as persistant global variables in a project suite. I've read all the posts/documentation and I still don't how you set these thing.

 

I set them in my project via the projectsuite (or project level) and they just don't persist. Frankly I'm tired of playing with it and I just want to make them available everywhere. 

 

Any suggestions on how to best do this? If anyone can explain how to set these to be persistant and projectsuite level that'd be great too because I'm just not getting it.

 

The variables are being created as persitant, but not set as persistant...??

 

 

Thanks,

Rob

 

  • Hi Rob,

     

    Yes, Project or ProjectSuite variables are global for the whole project or project suite respectively.

    They can be either persistent or temporary. Both of them can be assigned values to, but the former persists assigned value into the project file (and thus the value is preserved between test runs) while the latter does not persist. Note, that as persistent variable saves its value into the project file, the file is marked as changed by OS and you may be getting notifications from OS and version control system about changed source file.

     

    The values of your project suite variables do not change because a new value is not assigned to them.

    One possible modification of your code:

    function SetInnovationsVariables()
    {
        ProjectSuite.Variables.ArchivePath = AssignPathVariable("ArchivePath","String","Archive");
        ProjectSuite.Variables.OutgoingPath = AssignPathVariable("OutgoingPath","String","Outgoing");
          
        Log.Message(ProjectSuite.Variables.OutgoingPath); 
    }
    

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Rob,

     

    Yes, Project or ProjectSuite variables are global for the whole project or project suite respectively.

    They can be either persistent or temporary. Both of them can be assigned values to, but the former persists assigned value into the project file (and thus the value is preserved between test runs) while the latter does not persist. Note, that as persistent variable saves its value into the project file, the file is marked as changed by OS and you may be getting notifications from OS and version control system about changed source file.

     

    The values of your project suite variables do not change because a new value is not assigned to them.

    One possible modification of your code:

    function SetInnovationsVariables()
    {
        ProjectSuite.Variables.ArchivePath = AssignPathVariable("ArchivePath","String","Archive");
        ProjectSuite.Variables.OutgoingPath = AssignPathVariable("OutgoingPath","String","Outgoing");
          
        Log.Message(ProjectSuite.Variables.OutgoingPath); 
    }
    

     

    • rmnrdi's avatar
      rmnrdi
      Contributor

      That fixed it.

       

      You are the best!