Ask a Question

using global variables in test complete


using global variables in test complete

I have code set up in 2 separate run scripts based on my testing needs. Steps:


1) want to execute test script #1 (see below)

2) then I will be executing a keyword test

3) then execute test script # 2 (see below)


I defined a global variable in test script #1 below. I then need for test script #2 to use the global variable from test script #1. How do I code test script #2?


Test script #1:


function test ()



var page = Sys.Browser("iexplore").Page("").Form("aspnetForm");

var state = page.elements.__VIEWSTATE.value }


//Global variable:


function testProcedure(page1)


page1 = page.elements.__VIEWSTATE.value; }


Test script #2:


function test ()


var page = Sys.Browser("iexplore").Page("").Form("aspnetForm");

var x = page1 (this does not worked coded this way). Error message saying "page1" is undefined

var newstate = page.Elements.__VIEWSTATE.value;

if (state == newstate)

   Log.Message ("Postback hasn't been invoked");


   Log.Message ("Postback has been invoked"); }


Hi blacy


If I understandyou well. You want to share a variable from script one to script to.  

There are many posibilities. 


The easyest one would be just creating a Project variable. (Double click into your project. Variable Tab. Create one it, choose type...)

   From script 1 save the value into that variable. 

      Project.Variables.YOUR_VARIABLE = "whatever"

   From Script 2

      blahblah = Project.Variables.YOUR_VARIABLE



Another aproach would be to read from Script 2 the variable straight from the Script1. For that you have to import the Script1 from the Script2. Just add on top Script 2: 'USEUNIT Script1




function function_return_value
    function_return_value = "some_value_in_script1"
end function


'USEUNIT Script1

sub subs_cannot_retur_values
    thisValue = Script1.function_return_value()
end sub

Functions can return values.

Subs cannot return values.



Note about project variables. 

Persistent variables will remain after test run. 

Temporally variables will be clean after test run.


Hope this example helps you




Showing results for 
Search instead for 
Did you mean: