I'm preparing data to be sent as part of HTTP request, so the data preparation part is being done in BeanShell preprocessor.
As the request size changes, I need a variable length of JSON to be passed. I am creating JSON body in for loop, but the parameters are not changing, Ex:
try{
int[] po = {20, 30, 40, 50, 75};
int rNum = getRandom(0,4);
String name="${name}";
String _class="${_class}";
StringBuilder msgBody = new StringBuilder();
msgBody.append("{\"name\":\"")
.append(name)
.append("\", \"class\":\"")
.append(_class)
.append("\", \"marks\":[");
for (int i=0;i<po\"[rNum];i++)
{
msgBody.append("{ \"subject\":\"${__P(marks${line_offset})}\"," },");
}
int length=msgBody.length()-1;
log.info(String.valueOf(length));
msgBody.setLength(length);
msgBody.append("] }");
vars.put("json",msgBody.toString());
}
${__P(marks${line_offset})}
remains same inside the loop.
How to enable the change inside loop?