简体   繁体   English

JMeter | 如何定义变量,使其范围在BeanShell中的{thread,Thread-Group,Test-Plan}中

[英]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. 现在尝试创建多个Thread-Group并在每个中添加这个BeanShell采样器。

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.? 如何使变量仅在Thread-Group的所有线程中可用(而不是在其他线程组上)。在不同的线程组中提供常量唯一名称不是一种选择。

Could somebody help me. 有人能帮助我吗? Thanks in advance. 提前致谢。

Add BeanShell Sampler and insert this code: 添加BeanShell Sampler并插入以下代码:

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

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Jmeter 中运行 Postman 测试? ; 当您有多个采样器时,如何在测试计划/线程组中运行单个采样器? - How to run Postman tests in Jmeter? ; How to run single sampler inside a Test Plan/ Thread group when you have multiple sampler inside it? Jmeter select 来自先前线程组变量的随机值 - Jmeter select a random value from previous thread group variables jmeter设置线程组 - jmeter setup thread group 如何在jmeter中检查线程组停止执行 - How to check thread group stopped execution in jmeter 我们可以在Jmeter的单个测试计划中并行运行两个线程组吗? - Can we run two thread groups parallely in a single test plan in Jmeter? 如何在具有特定吞吐量的一个线程组中创建具有并行执行的 JMeter 测试? - How to create JMeter test with parallel execution in one thread group with specific throughput? 使用1个线程进行一个循环并使用线程组内的吞吐量控制器时,测试计划不会执行 - test plan is not getting executed while using 1 thread for one loop and using throughput controllers inside the thread group 如何在Jmeter中计算负载曲线并选择螺纹组 - How to calculate load profile and choose thread group in Jmeter 如何在 JMeter 中将变量从一个线程组传递到另一个线程组 - How do I pass a variable from one Thread Group to another in JMeter 停止测试和停止测试之间的JMeter差异现在线程组中的单选框 - JMeter differences between stop test and stop test now radio boxes in Thread Group
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM