Jmeter variable from Javascript
1. Create "User Defined Variables"

Variable SCRIPT:
var randomstring = ”; var chars = "abcdefghiklmnopqrstuvwxyz";for (var i=0; i<Math.floor(Math.random()* 10-5); i++) {var rnum = Math.floor(Math.random()* chars.length);randomstring+=chars.substring(rnum,rnum+1);}randomstring;

Originally from:

<script language="javascript" type="text/javascript">
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
document.randform.randomfield.value = randomstring;

There is no need to escape the commas in the SCRIPT variable, because the above statement is parsed before the the variable is replaced by
its contents.

2. Use Variable in JMeter Sampler:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s