Best solutions: Saving values and writing to external files during a load test

Performance testing

Learn more about continuous performance testing and how to deliver performance at scale.


Tricentis Staff

Various contributors

Date: Feb. 12, 2020

During your load test, you may want to log information related to your script. This is useful if you want to check data afterward, whether it was used or modified during your load test.

There are a few ways to log data during your tests:

  1. You can use the NeoLoad logger JavaScript class to log your information. The data will be stored in the load generator log files.; Note: The logging level can be configured in the project settings in the Runtime parameters section.
  2. You can write to .bin files directly from NeoLoad (only for responses, see below).
  3. You can use a specific JavaScript with a defined variable. The data will be stored in a file of your choice. Create this JavaScript in the NeoLoad JavaScript libraries folder:

//Script to write variable to external file

var lock = new java.util.concurrent.locks.ReentrantLock();

var date = context.variableManager.getValue(“CurrentDate”);

if (date==null)

{“Variable ‘CurrentDate’ not found”);


function writeFile(text)



var writer = new“c:\log.txt”,true);






Note: if you use it inside the JavaScript library, copy all the code inside the function; otherwise, the compilation won’t work. If you use all the code inside a NeoLoad JavaScript, you can leave it as is.

Pre-requisite: “CurrentDate” is a NeoLoad variable (see Variable manager, create it) that will display the current date. It’s optional and can be replaced with any variable needed.

Note: “” will display the instance of the VU; it’s also optional. And then insert this JavaScript to use the function:

//Script to get variable from running test

var cpt = context.variableManager.getValue(“StringNameFooBar”);

if (cpt==null)

{“Variable ‘StringRandom’ not found”);


writeFile(cpt+”;was the value from my test”);

Note: “StringRandom” is a Neoload variable; it’s optional and can be replaced with any other variable needed.

For more information, see Use the Javascript API in Neoload documentation.

Writing data via the GUI

In NeoLoad, it is possible to write content to a file from the GUI interface of a specific response given during playback or test. The Response storage checkbox makes it possible to save the content of the response in a .bin file. This function stores the content of the response on the machine executing the virtual users to check it externally. Here’s how:

  1. Create a test recording in a project to use.
  2. Define a file to write to and select the option “Write response to a file” under the Advanced Settings tab of one of the recorded actions. (Navigate by double-clicking on a node endpoint and clicking “Advanced”). The dialogue looks like this:

  1. After selecting the checkbox to write to a file a .bin file is provided in the /responses/ directory
    1. The option “Write response to a file” must be selected to enforce the storage function:
    2. The field “Path and template of the file to create” contains the file path relative to the storage folder —%AppData%NeotysNeoLoadv5.4— as described in NeoLoad files. The field also includes the template of the default filename response{ID}.bin. The {ID} variable is replaced with a unique integer. A single file is generated each time the request is executed.
  2. The optional field “Store evaluated file path in the variable” may be used for the virtual user variable (runtime variable), which will contain the absolute path of the storage files generated during the test campaign.
  3. The option “Delete the file when the test stops” must be cleared to keep the files once the test is over. When the options box is selected, the files are available when the test is running only. Run the test and view the selected .bin files for review of data exported during the test.

Writing to a file with command-line action

The goal of this technique is to capture an extraction and write this value to a file. NeoLoad has an advanced action, under the “Launchers” section, called “command line.”

Combine this technique with a shell script to better enhance the data manipulation should you need to. To use the command line, drag the action into your User Path, and add the required parameters. As you can see in the figure below, I’m calling the shell script and then pushing data from the extraction (variable) that I’m getting from the response.

Here is the simple shell script that is being called:


echo $1 >>/Users/neotys/Desktop/nl_text.txt

[H2] Next steps: Review documentation or talk to us

Check out all of the content included within NeoLoad documentation.

Want to discuss further, contact support.

Performance testing

Learn more about continuous performance testing and how to deliver performance at scale.


Tricentis Staff

Various contributors

Date: Feb. 12, 2020

Related resources