JMeter | How to define variables such that their scope is in {thread, Thread-Group, Test-Plan} from within BeanShell

Rajan picture Rajan · Oct 7, 2013 · Viewed 8.7k times · Source

I am trying to write a test plan, where a custom report is generated based on the text on the samplers. I could not scope the variables correctly in these three levels.

loc = vars.get("local_count");
if(loc == null){
   vars.put("local_count", "1");//available only in local thread level
}else{
   temp = Integer.parseInt(loc) + 1;
   vars.put("local_count", temp.toString());
}
log.info("the local count is " + vars.get("local_count");

glo = props.get("global_count");
if(glo == null){
   props.put("global_count", "1");//available in test plan level
}else{
   temp1 = Integer.parseInt(glo) + 1;
   props.put("global_count", temp1.toString());
}
log.info("the global count is " + props.get("global_count");

Now try creating multiple Thread-Group and add this BeanShell sampler in each of them.

How to make a variable available in all the threads of a Thread-Group only(not on other thread groups).Providing constant-unique names in different thread groups is not an option.?

Could somebody help me. Thanks in advance.

Answer

Bobur Meliev picture Bobur Meliev · Oct 7, 2013

Add BeanShell Sampler and insert this code:

vars.put("test","abcd");

enter image description here