Manages NeoLoad variables.
There are several types of NeoLoad variables:
These variables are explicitly declared in the Variables panel in NeoLoad. They have a "value change policy" that defines when they should take a new value.
These variables are set at runtime, using Variable Extractors for example. Their values must be explicitly changed to another value.
These variables are explicitly declared in the NeoLoad Variable Manager. They work on the "Producer/Consumer" model, meaning that values generated from variables or extractors can be added to the queue then later consumed.
The Variable Manager allows you to:
public class VariableManager {
// Public Methodspublic boolean addSharedValue(String variableName,
String value);
public void changeValue(String variableName);
public boolean createSharedQueue(String variableName,
int queueSize,
int timeout);
public boolean createSharedQueue(String variableName,
int queueSize,
int timeout,
String filename,
char delimiter,
boolean swapLoaded,
boolean swapDumped);
public int getSharedQueueSize(String variableName);
public String getValue(String variableName);
public String parseString(String text);
public String peekSharedValue(String variableName);
public String pollSharedValue(String variableName);
public void setValue(String variableName,
String value);
}
public boolean addSharedValue(String variableName,
String value);
Parameters
variableName
value
return
true
if the value has been successfully added to the queue and the maximum capacity has not been exceeded.Adds a value to the shared queue.
If the queue has reached its maximum capacity, the value will not be added and the function returns false
public void changeValue(String variableName);
Parameters
variableName
Change the value of a declared variable, such as a File variable or a Counter variable.
public boolean createSharedQueue(String variableName,
int queueSize,
int timeout);
Parameters
variableName
queueSize
timeout
return
true
if the queue has been successfully created and the variable does not exist.Creates a queue that is shared between the Virtual Users.
public boolean createSharedQueue(String variableName,
int queueSize,
int timeout,
String filename,
char delimiter,
boolean swapLoaded,
boolean swapDumped);
Parameters
variableName
queueSize
timeout
filename
set
Optional
swapLoaded
true
if the queue is to be populated from the swap file at the start of the test.swapDumped
true
if the queue is to be saved to the file at the end of the test.return
true
if the queue has been successfully created and the variable does not exist.Creates a queue that is shared between the Virtual Users associated with a CSV swap file.
public int getSharedQueueSize(String variableName);
Parameters
variableName
return
Returns the number of items in the shared queue, -1
if the queue does not exist.
public String getValue(String variableName);
Parameters
variableName
return
Returns the value of a variable or null if the variable does not exist.
parseInt(varname)
or parseFloat(varname)
for example. // variable value is "45"
var varAsString = context.variableManager.getValue("myVar");
var varAsInt = parseInt(varAsString);
varAsString = varAsString + 1; // New value is "451"
varAsInt = varAsInt + 1; // New value is "46"
public String parseString(String text);
Parameters
text
return
Evaluate a string that contains variables. For example, "the counter value is: ${counter}" will return "the counter value is: 7".
public string peeksharedvalue(string variablename);
Parameters
variableName
return
Returns the first value in the shared queue without deleting it, or null
if the queue does not exist.
If the queue does not contain any values, the value returned will be in the form ${variableName}
// The value of the variable is "45"
var varAsString = context.variableManager.peekSharedValue("myVar");
var varAsInt = parseInt(varAsString);
varAsString = varAsString + 1; // The new value is "451"
varAsInt = varAsInt + 1; // The new value is "46"
public String pollSharedValue(String variableName);
Parameters
variableName
return
Returns the first value in the shared queue and deletes it, or null
if the queue does not exist.
If the queue does not contain any values, the value returned will be in the form ${variableName}
// The value of the variable is "45"
var varAsString = context.variableManager.pollSharedValue("myVar");
var varAsInt = parseInt(varAsString);
varAsString = varAsString + 1; // The new value is "451"
varAsInt = varAsInt + 1; // The new value is "46"
public void setValue(String variableName,
String value);
Parameters
variableName
value
Assigns a value to a runtime variable. The variable is created if it does not exist. Note that the variable name should be used, not the variable expression: use 'varname' and NOT '${varname}'. Nevertheless, the name can be compound, for example: "data_for_${login}" if variable "data_for_jsmith" is defined.
When using the name of a declared variable, a runtime variable will be created that will override the declared variable. Overriding declared variables is not recommended.