How to get the name of JMX Jmeter filename in a variable

戏子无情 提交于 2019-12-06 07:01:47

The variable that holds the test plan name is ${__TestPlanName}

Ref: http://jmeter.apache.org/usermanual/functions.html#__TestPlanName

You can do it via Beanshell scripting like:

  1. GUI mode

    import org.apache.jmeter.gui.GuiPackage;
    
    String scriptName = GuiPackage.getInstance().getTestPlanFile();
    vars.put("scriptName", scriptName);
    
  2. non-GUI mode

    import org.apache.jmeter.services.FileServer;
    
    String scriptName = FileServer.getFileServer().getScriptName();
    vars.put("scriptName", scriptName); 
    

Put the code snippet of your choice into any "Beanshell" test element (sampler, pre/post processor, or assertion), it will get .jmx test script name and store it into ${scriptName} variable.

To learn more about Beanshell scripting in JMeter check out How to use BeanShell: JMeter's favorite built-in component guide.

Below would work irrespective of GUI / Non GUI mode:

import org.apache.jmeter.services.FileServer;
import java.io.File;

String testPlanFile = FileServer.getFileServer().getBaseDir() +
                       File.separator +
                       FileServer.getFileServer().getScriptName();

props.put("testPlanFile", testPlanFile);

Use this as ${__P(testPlanFile)} - Adding it as var would not work across all threads. From http://jmeter.apache.org/usermanual/functions.html -

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!