我想使用JMeter中的BeanShell预处理器为事务控制器指定名称。我想在以后使用标头管理器连接并在dynaTrace中显示。
我使用BeanShell侦听器尝试过类似的操作
String test = sampleResult.getSampleLabel();
log.info(test);
Run Code Online (Sandbox Code Playgroud)
但是我想使用预处理器。
log.info(sampler.getName());
Run Code Online (Sandbox Code Playgroud)
这用于获取采样器的名称,就像我想要获取事务控制器的名称一样。
具体来说,我想使用BeanShell预处理器。
有人可以帮我吗?
您不能比“ 以前的结果”或“ 以前的采样器”走得更远,所以我要说这不是您可以轻松实现的东西。看起来您的测试设计得不太好,因为通常人们不需要知道父采样器控制器的名称。
尽管如此,您仍可以访问JMeter测试计划树并从那里查找信息。示例代码如下所示:
import org.apache.jmeter.control.TransactionController;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jorphan.collections.HashTree;
import org.apache.jorphan.collections.SearchByClass;
import java.lang.reflect.Field;
import java.util.Collection;
StandardJMeterEngine engine = ctx.getEngine();
Field test = engine.getClass().getDeclaredField("test");
test.setAccessible(true);
HashTree testPlanTree = (HashTree) test.get(engine);
SearchByClass txnCtrlSearch = new SearchByClass(TransactionController.class);
testPlanTree.traverse(txnCtrlSearch);
Collection txnControllers = txnCtrlSearch.getSearchResults();
for (Object txnController : txnControllers) {
    log.info(((TransactionController) txnController).getName());
}
Run Code Online (Sandbox Code Playgroud)
演示:
有关从Beanshell脚本使用JMeter API的一些信息:如何使用BeanShell:JMeter的最喜欢的内置组件
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1807 次  |  
        
|   最近记录:  |