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?

Support
Support

Support

Level
0
-10 / 100
points
Team
Support
Support

Support

Level
0
-10 / 100
points
Team

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. logger.info(myMessage);

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) 
{
 context.fail("Variable 'CurrentDate' not found");
}
function writeFile(text) 
{
lock.lock();
var writer = new java.io.FileWriter("c:\\log.txt",true);
writer.write(date+";"+context.currentVU.id+";"+text);
writer.write("\r\n");
writer.close();
 
lock.unlock();
}

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: "context.currentVU.id" 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) 
{
 context.fail("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%

89% of users found this answer useful