API overview

This section gives an overview of the JavaScript Action API. For more information, see Javascript Action API.

Execution context

NeoLoad provides an execution context for each script in order to manipulate variables, errors and cookies: the predefined context variable which allows procedures to be carried out on the Virtual User being executed.

For more information, see Class RuntimeContext.

Manage variables

NeoLoad features a Variable Manager, which allows the user to retrieve the value of a variable, create a new variable, or increment the value of a variable defined in NeoLoad. The Variable Manager is accessed through the context.variableManager context.

For example, the following script retrieves the value of a NeoLoad variable, changes the value, and uses the new value to create a new variable. This new variable may now be integrated into the User Path actions, for example inserted in a form.

var varMng = context.variableManager; 
var searchID = varMng.getValue("searchID"); 

For more information, see Class VariableManager.


The logger keeps a trace of information when a script is run by writing entries to the Check User Path log file (loadGenerator.log.00x in the logs folder) and in the NeoLoad interface in the event of an error.

There are five levels, in the decreasing order of severity:

You may set the maximum level to be used in the Runtime parameters section accessible through Edit > Preferences > Project settings.

When checking a User Path, the DEBUG level is selected automatically.

The following example is a script writing an error message to the logs.

logger.error("Invalid value: "+myvar);

For more information, see Class Logger.

Error management

When executing a JavaScript script, it is possible both to error-flag the action and stop its execution. The error is then displayed in the test results. The error contains the error message and the appropriate-level logs.

The following example is a script flagging an action as an error.

context.currentVU.fail("Invalid value: "+myvar);

For more information, see Class VirtualUser.

Add a cookie

The API also allows the user to add a cookie for a given server while a Virtual User is being executed. For more information, see Javascript Action API.

For more information, see Class VirtualUser.

Script example
var varMng = context.variableManager; 
// Retrieves the searchID variable extracted from a request preceding this JavaScript 
var searchID = varMng.getValue("searchID"); 
// Log the searchID value in debug mode 

// Error management if searchID variable is missing 
if(!searchID) { 
   // Stop script execution and prompt the NeoLoad error 
   context.fail("variable SearchID not found"); 

// Create a new cookie for server 'myServer_80' 
        "cookieName="+searchID+"; Expires=Sat, 30-Sep-2006 21:03:07 GMT; path=/" 

// Create a new runtime variable named 'newSearchID' 
// Note: all NeoLoad variables are character strings, 
// they may need to be converted using the following 
// methods parseInt(), parseFloat(),... 
var newSearchID = parseInt(searchID)+1;
Java libraries

NeoLoad allows using Java classes and methods in JavaScript actions. To use a Java library, simply copy the .JAR files into the <NeoLoad-project>/lib/jslib directory. The added files will be automatically taken into account.

The class names must be fully qualified within the JavaScript, (even for the Java classes like java.util.List) and preceded by Packages.

For example:

var myObj = new Packages.com.company.MyClass(); 
var result = myObj.compute(myArg); 
var result2 = Packages.com.company.MyClass.someStaticMethod(result);