Forum Discussion

sridhar_t's avatar
sridhar_t
Occasional Contributor
11 years ago

Accessing global variable values

Hi All,



Is there a way to access the values of the global variable in my case an array which gets value stored during the run time . 





To be specific consider there are 2 scripts unit1 and unit2 in unit1 I have declared an array say company(5) during run time the company array gets it value from a procedure in unit1 script. Can I access these values in procedures of script unit2 



Regards,

Sridhar

3 Replies

  • chrisb's avatar
    chrisb
    Regular Contributor
    You could also try using the project and project suite variables. The variables and data will persist between test runs but you can always write a helper function to delete them when you are done. I use the project suite variables in my test runs for sharing data between scripts and it works great. In some cases I want the variables to persist between test runs and  in some I only need them to be temporary. For the latter case I have a script that deletes them at the end of a test run.



    http://support.smartbear.com/viewarticle/55666/

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Depending upon your script language the actual command may differ.  but, for JScript, you can use







    at the beginning of your unit 2.  You can then call the variable as unit1.company.
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    The short answer is yes.

    The complicated answer is that you may not have a circular reference.

    That is UNIT2 cannot reference UNIT1 if UNIT1 already references UNIT2.

    If you need to access the same variables from each script consider adding a third unit.

    You'll want to use the USEUNIT statement in the beggining of your script to link scripts:

    http://support.smartbear.com/viewarticle/8921/?st=0



    Then declare the global variable outside a function.

    JScript Ex:



    Unit1:

    //USEUNIT UNIT3



    function main(){

    dostuff();

    }



    Unit2:

    //USEUNIT UNIT3



    function main2(){

    dootherstuff();

    }



    Unit3:


    company = new Array(5);