Access to JMeter script path

I used the answer provided by haridsv. It worked great except that I needed to put the directory to the JMX file in a variable. I made a "User Defined Variables" component and used BeanShell in the variable's "Value" field like this:

${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}

The first BeanShell section calls the Java class that gets the directory in question. The second appends a file separator to the path, which is of course optional.


  • Include Controller
    As per component's reference:

    This element does not support variables/functions in the filename field.
    However, if the property includecontroller.prefix is defined, the contents are used to prefix the pathname. If the file cannot be found at the location given by prefix+filename, then the controller attempts to open the fileName relative to the JMX launch directory (versions of JMeter after 2.3.4).

    You can pass JMeter a java property named includecontroller.prefix which can be used to prepend a directory to the JMX file you're including.

    1) In case of console launch use:

    -Jincludecontroller.prefix=/full/path/to/jmx/scripts/dir/

    2) in case of GUI - add the same to .sh/.cmd/.bat file or write a wrapper file;
    3) in case of Jmeter Ant Task usage - set as separate property:

    <jmeter 
    jmeterhome="${jmeter.home}" 
    testplan="..." 
    resultlog="...">
        <property name="jmeter.save.saveservice.assertion_results" value="all"/>
        <property name="jmeter.save.saveservice.output_format" value="xml"/>
        <property name="includecontroller.prefix" value="..."/>
    </jmeter>
    
  • CSV Data Set Config
    As per component's reference:

    Relative file names are resolved with respect to the path of the active test plan.
    Absolute file names are also supported, but note that they are unlikely to work in remote mode, unless the remote server has the same directory structure. If the same physical file is referenced in two different ways - e.g. csvdata.txt and ./csvdata.txt - then these are > > treated as different files. If the OS does not distinguish between upper and lower case, csvData.TXT would also be opened separately.


    You can declare a test plan variable that retrieves parameter value with the folder containing csv data files:
    e.g.

    csv.path | ${__P(csv.path, ${__property(user.dir)}${__BeanShell(File.separator,)})} 
    CSV Data Set Config
    Filename = ${csv.path}${__P(users-list,)}
    

    Setting from console:

    -Jcsv.path=/full/path/to/csv/data/dir/

    Setting for distributed testing setup:

    -Gcsv.path=/full/path/to/csv/data/dir/

Tags:

Java

Jmeter