Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 335
Rajan Avatar asked Oct 07 '13 10:10

Rajan


1 Answers

Add BeanShell Sampler and insert this code:

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

enter image description here

like image 81
Bobur Meliev Avatar answered Oct 15 '22 09:10

Bobur Meliev