Forum Discussion

blacy's avatar
blacy
Contributor
10 years ago

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("https://staging.studies.jaeb.org/ndocs/sysdev/Tests/JaebWeb/BasicControlsAndJfe/Validations/TextBox/TextBoxRequiredClient.aspx").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("https://staging.studies.jaeb.org/ndocs/sysdev/Tests/JaebWeb/BasicControlsAndJfe/Validations/TextBox/TextBoxRequiredClient.aspx").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");

else

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

  • Lage's avatar
    Lage
    Contributor

    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 variable...name 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

     

     

    Script1:

    function function_return_value
        function_return_value = "some_value_in_script1"
    end function

    Script2:

    'USEUNIT Script1
    
    sub subs_cannot_retur_values
        thisValue = Script1.function_return_value()
        Log.Message(thisValue)
    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

     

    Regards,

    Lage