Search code examples
jmeterjmeter-plugins

Jmeter Cross-Platform Path config issue


I am working on master-slave Jmeter configuration, my data set exist on each machine on a different path for (macOS, Windows).

I use a global data set to fetch data for multiple thread groups. reading student data However, the variable/property can be different across platforms.

I also tried the JSR223 to check the, but still no luck. check out the below snapshot. JSR223

I am trying to make sure that once I ran my test from Master (Mac), it also run on Windows.

Any thoughts how to do that on multiple platform setup.


Solution

  • The best solution is placing your test data under the same path which will be relative to JMeter working directory, this way you will not have to change anything in your script.

    If for some reason you cannot afford this you can add a JSR223 Sampler to your Test Plan and use the code like:

    if (org.apache.commons.lang3.StringUtils.containsIgnoreCase(System.getProperty('os.name'), 'Windows')) {
        vars.put('data-path', 'c:/windows/specific/path')
    } else {
        vars.put('data-path', '/macos/specific/path')
    }
    

    It will detect the operating system name in the runtime and you will be able to define an OS-specific paths using the above approach.

    vars is a shorthand for JMeterVariables class instance, the above code defines ${data-path} JMeter Variable which you can use later on for specifying data files locations. See Top 8 JMeter Java Classes You Should Be Using with Groovy to learn more about JMeter API shortcuts exposed to JSR223 Test Elements