Bean shell scripting - Examples

Add a thread group and add a BeanShell Sampler to ur test plan

Let us go to our test plan and add a variable named x and give it value hello.

In BeanShell Sampler the following variables are defined for the script...

Then in BeanShell Sampler in Script(See below for variables.....) we type

print(vars.get("x"));

Then after that script in bean shell we can add a Results tree to our Thread Group to check the result of bean shell sampler

Then let try some more commands in Bean Shell.

y=2;//Note in java have to give data type i.e int y=2; but BeanShell is very light weight so we dont have to give data type while declaring variables.
int x =1;//but we can even give the variable data type as well.It will accept it.
print(y);

Simlarly we can change value of variable x that we defined in jmeter

vars.put("x","newHello");
print(vars.get("x");