7

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.

Rajan
  • 1,501
  • 4
  • 21
  • 37

1 Answers1

4

Add BeanShell Sampler and insert this code:

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

enter image description here

Bob Meliev
  • 1,198
  • 12
  • 17
  • 4
    That variable's scope will be thread level only. If you run the script in multiple threads - and modify the variable differently(append separate characters) in each thread,log.info() the result and see, it will not work as expected. – Rajan Oct 07 '13 at 11:50