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

半腔热情 提交于 2019-12-10 10:57:56

问题


I want to use the name of the jmeter test script (.jmx) in a listener so as to generate the result file in a dynamic way. Can you please tell me what is the Jmeter variable for that purpose?

Used ${fileName} which didn't work


回答1:


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

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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/31157927/how-to-get-the-name-of-jmx-jmeter-filename-in-a-variable

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