Defining Functions

Top  Previous  Next

Purpose

The SmarteStudio test script is in Javascript.  You may define as many Javascript functions as you would like to call from your test script.

 

Usage

There are two ways to maintain additional functions: (1) Inside your test script and (2) in an external file.

 

Inside your Test Script

Define the function inside of one of the following functions: Test(), TestInit(), TestFinish(), or TestPrepare().  The Script Recorder will erase code placed outside of these functions.

 

Inside  *.user.js File

It is recommended to put all user functions into <testname>.user.js file available in any test from its creation.

 

test files dialog, user script

This file is automatically attached into every script. All variables and functions defined in it may be used in the test. User-defined functions are also available under the "User Functions" node in the Object Tree:

object tree dialog user functions

 

 

In an External File

You can define your function in another file and include it.

 

For example:

function Test()

{

       // Withdraw is defined inside the "Test" function

       function Withdraw(amount)

       {

               Log("Start Withdraw of:"+amount);

               // Withdraw logic is here

       }

       

       Withdraw(12.34);

       

       // Include "UtilityFunctions.js" to get at function Deposit()

       eval(g_helper.Include(Global.GetFullPath("UtilityFunctions.js")));

       // Deposit is defined in "UtilityFunctions.js"

       Deposit(56.78);

}

 

See Also

To learn more about what the Script Recorder will change in your test script, see Multiple Recordings.