2

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

user2885295
  • 329
  • 1
  • 4
  • 12

3 Answers3

3

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.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
2

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

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

RaGe
  • 22,696
  • 11
  • 72
  • 104
2

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.

Pavan Kumar
  • 4,182
  • 1
  • 30
  • 45