BSF sampler in jmeter

BSF Sampler can use many coding languages. We can add a BSF sampler as we add other sampler to a thread group.

We can work with any language in BSF sampler.Most popular language used with bean shell is groovy,javascript and java.

For using BSF Sampler the precondition is that there should be a file named bsf-2.4.0 in the folder where our jmeter in lying like in our case it is C:\Jmeter\apache-jmeter-2.13\lib.

After adding a BSF sampler to our thread group, we can add a result tree to the thread group as well.

In BSF sampler we can go to language and choose bean shell.

In the code section we can type

Print(“hello”);

Then we run our test plan hello will be printed in cmd as we have choosen the Language as bean shell.

We can choose the language as groovy.But there is a pre-condition for that.we have to choose…

Go to Google.com and search download groovy jar.

http://www.java2s.com/Code/Jar/g/Downloadgroovyallminimal157jar.htm

Download the binary file and put in lib folder. Then restart jmeter.

Then add a new thread and in that add a new BSF Sampler.In that choose language as add groovy and in code type

OUT.println("groovy");//This will print groovy in cmd console.

Then add a new Thread Group.Add a BSF sampler.Add a http req. In that in url add google.com and in path put /.

To that http req add a BSF PostProcessor.Name it BSF PostProcessor-javascript

In lang choose java script.

In code we type

var content = prev.getResponseDataAsString();//used to get Response Message as a variable which we
//can print on new line
OUT.println(content);
log.info("Jmeter log "+content);//or we can put the ResponseMessage in log file instead of printing it.
prev.setResponseCode(400);//We can change ResponseCode or Response Message as well.
prev.setResponseMessage("Okay");

//we can play around with other artihmetic operations as well
var x = 3;
var y = 4;
var sum = x +y;
OUT.println(sum);
OUT.println(x + " abc");