Forum Discussion

joffre's avatar
joffre
Regular Contributor
13 years ago

How to set Global Variables?

Is it possible to create a variable that can be seen on the entire Project?



I'm using TestComplete 7.52.

6 Replies

  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)

    Hi Joffre,

    You got the general idea: project and project suite variables are available to any test within a project or project suite. However the actual value retrieved from a variable would depend on whether it is declared as persistent or temporary. Persistent variables store their values unless they are explicitly re-assigned. Temporary variables reset their values to the default value each test run. See Project and Project Suite Editor - Variables Page.





    Let me give an example:

    Case A: Suppose, we have a project variable - Project.Variables.NomeServidor, its default value is "SRV-Def", and the variable is Persistent. In one of the tests, we re-assign its value to "SRV-TSBD-9I". Afterwards, the actual value of Project.Variables.NomeServidor in this test and in all the rest of the tests will be recognized as "SRV-TSBD-9I".





    Case B: Suppose, we have a project variable - Project.Variables.NomeServidor,  its default value is "SRV-Def", and the variable is Temporary. In one of the tests, we re-assign its value to "SRV-TSBD-9I". Afterwards, the actual value of Project.Variables.NomeServidor in this test instance will be recognized as "SRV-TSBD-9I". However, for all the other tests, the value of Project.Variables.NomeServidor will still be recognized as "SRV-Def".





    PS. Also, note that project variables are accessed through the Project.Variables.<Variable_name> syntax. The Project.Variables part cannot be omitted.





    Regards.
    • Kaloyan's avatar
      Kaloyan
      Occasional Contributor

      Hi Guys,
      I am using project temporary variable Var1 with default value "Default".

      I have a project suit with two tests - Test1 and Test2. Test1 is executed first and then next test item is Test2.
      In Test1 i set the Var1 to "NewValue". When I ran my test suite and use the value of Var1 in my second test item "Test2" it's still "NewValue". 

      According to the above post Var1 should be with its default value "Default" since it is a Temporary variable and should not persist during the instances of different test items.
      Please correct me if I am wrong.

       

      Kind Regards

      ATQC Kaloyan Chipilev

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Unfortunately, you do happen to be incorrect.  The "temporary" designation for temporary project variables has to do with whether or not the value of the variable persists between test runs. So, you have a project... while running the project, you set the value of the variable.  So long as the project is running, that value persists unless it is changed.  When the project stops running, the value is cleared and the variable is reset to default.  

         

        Think of it as such:

         

        var tempVariable = 'default';
        
        function test1() {
            Log.Message(tempVariable);
            tempVariable = 'my test';
            Log.Message(tempVariable);
        }
        
        function test2(){
            Log.Message(tempVariable);
        
        }
        
        
        function foo() {
            test1();
            test2();
        }

        When you run function foo, the output should show in the log as

         

        default <- The log message before the variable value is set

        my test <- The log message in test1 after the variable value is set

        my test <- The log message in test2

         

        If you rerun function foo, you'll get the same output.

         

        Think of "foo" as your project and "tempVariable" as your temporary project variable.

  • joffre's avatar
    joffre
    Regular Contributor
    Is this correct?



    Project.Variables.NomeServidor = "SRV-TSBD-9I"

    Project.Variables.SenhaSystem = "ORCLTS9I"

    Project.Variables.NomeBase = "TS_A_ORA9_JO1"




    On this case, my variables 'NomeServidor', 'SenhaSystem' and 'NomeBase' will have this values on the entire project, correct?



    If in another script file I call "NomeServidor", it will be recognized as "SRV-TSBD-9I" ?