JMeter中如何获取线程和采样器名称
How to get the thread and the sampler name in JMeter
我想在 JMeter 测试计划中获取线程和采样器名称并将其保存在变量中。
我已经使用 BeanShell 保留了测试计划名称 Post 处理器:
import org.apache.jmeter.services.FileServer;
String testPlanName = FileServer.getFileServer().getScriptName();
vars.put("testPlanName", testPlanName)
我在电子邮件通知中使用它来发送消息,例如“测试计划 ${testPlanName} 已收到响应代码 ${responseCode}
但我想以同样的方式包含线程名称和采样器名称。
我已经尝试添加 BeanShell Post 处理器 .getThreadname() 和 .getSampleName() 并导入 import org.apache.jmeter.samplers.SampleResult;但它不起作用。
我怎样才能获得这些名称并将其用作变量?
一共有三个函数,你可以在BeanShell中使用:
-
The samplerName
function returns the name (i.e. label) of the current sampler.
The function does not work in Test elements that don't have an associated sampler. For example the Test Plan. Configuration elements also don't have an associated sampler. However some Configuration elements are referenced directly by samplers, such as the HTTP Header Manager and Http Cookie Manager, and in this case the functions are resolved in the context of the Http Sampler. Pre-Processors, Post-Processors and Assertions always have an associated Sampler.
示例:${__samplerName()}
-
The TestPlanName function returns the name of the current test plan (can be used in Including Plans to know the name of the calling test plan).
示例:${__TestPlanName}
注意,__TestPlanName将return测试计划的文件名,可以与测试计划名称不同。
-
The thread group name function simply returns the name of the thread group being executed.
示例:${__threadGroupName}
有关使用 BeanShell
的完整详细信息,请参阅:
您可以使用 BeanShell 将线程和采样器名称保存到参数中:
String _threadGroup = ctx.getThreadGroup().getName();
String _sampleName=ctx.getCurrentSampler().getName();
或
String _sampleLabel = SampleResult.getSampleLabel();
我想在 JMeter 测试计划中获取线程和采样器名称并将其保存在变量中。
我已经使用 BeanShell 保留了测试计划名称 Post 处理器:
import org.apache.jmeter.services.FileServer;
String testPlanName = FileServer.getFileServer().getScriptName(); vars.put("testPlanName", testPlanName)
我在电子邮件通知中使用它来发送消息,例如“测试计划 ${testPlanName} 已收到响应代码 ${responseCode}
但我想以同样的方式包含线程名称和采样器名称。
我已经尝试添加 BeanShell Post 处理器 .getThreadname() 和 .getSampleName() 并导入 import org.apache.jmeter.samplers.SampleResult;但它不起作用。
我怎样才能获得这些名称并将其用作变量?
一共有三个函数,你可以在BeanShell中使用:
-
The
samplerName
function returns the name (i.e. label) of the current sampler. The function does not work in Test elements that don't have an associated sampler. For example the Test Plan. Configuration elements also don't have an associated sampler. However some Configuration elements are referenced directly by samplers, such as the HTTP Header Manager and Http Cookie Manager, and in this case the functions are resolved in the context of the Http Sampler. Pre-Processors, Post-Processors and Assertions always have an associated Sampler.示例:
${__samplerName()}
-
The TestPlanName function returns the name of the current test plan (can be used in Including Plans to know the name of the calling test plan).
示例:
${__TestPlanName}
注意,__TestPlanName将return测试计划的文件名,可以与测试计划名称不同。
-
The thread group name function simply returns the name of the thread group being executed.
示例:
${__threadGroupName}
有关使用 BeanShell
的完整详细信息,请参阅:
您可以使用 BeanShell 将线程和采样器名称保存到参数中:
String _threadGroup = ctx.getThreadGroup().getName();
String _sampleName=ctx.getCurrentSampler().getName();
或
String _sampleLabel = SampleResult.getSampleLabel();