Monday, August 15, 2022

Capture the count of parameters in a file Neoload | Loop the parameter count times in Neoload | Neoload java script container

If you want to capture the count of parameters in a parameter file and loop the number of parameter times in  NeoLoad just use the java script code as below and get it done.

//Declare a variable in a file.Adjust the path to your file variable as necessary.

var fileName = "C:\\Users\\NeoloadScripts\\Desktop\\Userid.txt";

Note: you can use any file here either txt or csv or any other text formats

//Read the File and get line count


var reader = new Packages.java.io.LineNumberReader(new Packages.java.io.FileReader(fileName));
while ((reader.readLine()) != null) {}
var lineCount = reader.getLineNumber();
reader.close();



If a file variable has a column header line, alter the value by deducting 1 from the value; otherwise, don't use.

var lineCount = lineCount-1

//Log value of line count from file

logger.debug("Line number is = "+lineCount);


//Return to the Neoload script a variable with the value of the line count.


context.variableManager.setValue("LoopCount",lineCount);


After this java script go to the go to the loop and in the settings-execute loop enter ${LoopCount} as shown in below.



No comments: