Answered question

How do I save values and write them to an external file during a load test?

During a load test, I have a requirement to output dynamic values used for the virtual user instances to a separate file. How do I get Neoload to send these values during a test to an external file for review later?

During your load test, you may need to log some information related to your script. This is helpful if you want to check afterwards the data used or modified during your load test.


There are 2 ways for logging information during your tests:


a) 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.

b) You can use a specific javascript; The data will be stored in a file of your choice. You can create this javascript in the Neoload js libraries folder:


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 JS librairie, copy all the code inside the function otherwise the compilation won't work. If you use all the code inside a NeoLoad JS you can leave it as is.

Pre-requisite: "CurrentDate" is a Neoload variable (see Variable manager to create it) that will display the current date. It's optional.

Note: "" will display the instance of the vu, it's also optional.

And then create this kind of javascript to use that function:


var cpt = context.variableManager.getValue("StringRandom");
if (cpt==null) 
{"Variable 'StringRandom' not found");
writeFile(cpt+";was the value from my test");


Note: "StringRandom" is a Neoload variable, it's optional.


For more information about javascript, see "Neoload javascript API" under "Appendix" section in Neoload documentation.



Did you find this useful ?

No (1)

Yes (8)


89% of users found this answer useful