简体   繁体   中英

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.

Add BeanShell Sampler and insert this code:

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM