gpt4 book ai didi

variables - 如何在 JMeter 中获取线程和采样器名称

转载 作者:行者123 更新时间:2023-12-04 02:52:30 27 4
gpt4 key购买 nike

我想在 JMeter 测试计划中获取线程和采样器名称并将其保存在变量中。

我已经使用 BeanShell 后处理器保留了测试计划名称:

import org.apache.jmeter.services.FileServer;

String testPlanName = FileServer.getFileServer().getScriptName(); vars.put("testPlanName", testPlanName)



我在电子邮件通知中使用它来发送诸如“测试计划 ${testPlanName} 已收到响应代码 ${responseCode}

但我想以相同的方式包含线程名称和采样器名称。

我已经尝试添加 BeanShell 后处理器 .getThreadname() 和 .getSampleName() 并导入 import org.apache.jmeter.samplers.SampleResult;但它不起作用。

如何获取这些名称并将其用作变量?

最佳答案

共有三个函数,你可以在 BeanShell 中使用它们:

  • __samplerName()

    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()}
  • __TestPlanName()

    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 将返回 文件名 测试计划的名称,可以与测试计划名称不同。
  • __threadGroupName()

    The thread group name function simply returns the name of the thread group being executed.



    示例:${__threadGroupName}

  • 有关使用 BeanShell 的完整详细信息, 请参见:
  • JMeter with BeanShell Guide
  • BeanShell website
  • 关于variables - 如何在 JMeter 中获取线程和采样器名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54442577/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com