February 5, 2010

Passing Variables Between Scripts

Helix ALM
The quickest and easiest way to pass a variable value between scripts is to create a repository variable. A repository variable is a sort of “global variable”, accessible by all scripts that interact with an application. Repository variables are by default defined as text values, but can be converted to any type needed using the appropriate function or simply assigned a non-text value. In some cases, however, you may need to pass variable values to a script that interacts with a different application than the calling script. You may also want to know the current value of a variable after a called script has been executed. QA Wizard Pro contains two statements, GetScriptVariable and SetScriptVariable, that allow variable values to be passed between scripts. Below are two sample scripts that demonstrate how these statements work. Each example uses the ScriptName() function to assign a value. Copy the steps to two corresponding scripts, and run the main script to see how the SetScriptVariable statement works. Then comment out the SetScriptVariable steps in each script and run the main script again to see how GetScriptVariable works. Main.qawscript:
       '*** SetScriptVariable example
       X=1  'you will need to assign an initial value to the variable
       Script.CallScript("Called")
       println("X=" + X)

       '*** GetScriptVariable example
       'Z=ScriptName()
       'Script.CallScript("Called")
Called.script:
       '*** SetScriptVariable example
       SetScriptVariable("Main","X",ScriptName())

       '*** GetScriptVariable example
       'Y=GetScriptVariable("Main","Z")
       'println("Y=" + Y)
Another option available is to write the variable values to a datasheet or external file, and have the called script access the datasheet or file to retrieve the values.