If anyone wants to create a random string in Jmeter and use it for some purpose in your code , you can do that using the BeanShell Preprocessor .
The below code snippet can be used to generate a random string using BeanShell Preprocessor.
import java.util.Random;
chars = "1234567890abcdefghiklmnopqrstuvwxyz-";
int string_length = 36;
randomstring ="";
for (int i=0; i<string_length; i++) {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(chars.length());
randomstring += chars.substring(randomInt,randomInt+1);
}
vars.put("VAR_NAME",randomstring);
Place the random string into a variable of your choice by replacing the VAR_NAME with you variable name.
nice one
ReplyDeletePerfect. It Works like a Jem
ReplyDeleteimport org.apache.commons.lang.RandomStringUtils;
ReplyDeleteString AssetProductCode = RandomStringUtils.randomAlphanumeric(06).toUpperCase();
vars.put("AssetProductCode", AssetProductCode);
You can access above variable using: ${AssetProductCode}
I really like what you guys tend to be up too. Such clever work and reporting! Keep up the wonderful works guys I've included you guys to my own blogroll.
ReplyDelete