BSF pre-processor in jmeter

We can add a BSF pre-processor before any http or java request and in that we can try to change the value of a variable stored at Test plan level.

For example lets try to change the value of variable named Quantity using bean shell language in BSF pre-processor

oldQuan = vars.get("Quantity");
newQuan = Integer.parseInt(oldQuan)+10;
vars.put("Quantity",newQuan.toString());
print("The updated Qaun is "+ vars.get("Quantity"));

Now we can try the same things with bsf sampler but language can be changed from bean shell to javaScript.

In javaScript a few changes are req in code.

newQuan = Integer.parseInt(oldQuan)+10

becomes

newQuan = parseInt(oldQuan)+10

And print changes to OUT.println.

Now we can try the same things with bsf sampler but language can be changed from bean shell to groovy.

In groovy a few changes are req in code.

newQuan = Integer.parseInt(oldQuan)+10

becomes

newQuan = oldQuan.toInteger()+10;

And print changes to OUT.println.