0
votes

I am working quite some time with jMeter now but this is the first time I want to start several jMeter Tests from my own code.

Basically, I copied from here: 5 ways to launch jmeter test without using jmeter gui

The JMX-File has been created with the GUI containing two variables.

The HTTP Sampler contains in the "Server name or IP" field:

${__P(server)}

The Path field contains:

/${__P(target)}

The respective entries in the jmeter.properties file are:

server=127.0.0.1
target=README

When running in jMeter, both values get replaced and the correct URL is passed. When accessing the both properties during Runtime in my java code it yields the correct results.

When jMeter tries to replace my values, I get this message:

"Not running version, return raw function string"

I tried to trace down the problem in the jmeter sources but did not get to a result.

The Java code I use is:

public static void main(String[] args) throws IOException {

    StandardJMeterEngine jmeter = new StandardJMeterEngine();
    JMeterUtils.loadJMeterProperties("C:\\data\\apache-jmeter-2.13\\bin\\jmeter.properties");
    JMeterUtils.setJMeterHome("C:\\data\\apache-jmeter-2.13");
    JMeterUtils.initLocale();
    System.out.println("Property: " + JMeterUtils.getProperty("server"));
    SaveService.loadProperties();
    FileInputStream in = new FileInputStream("c:\\data\\test.jmx");
    HashTree testPlanTree = SaveService.loadTree(in);
    in.close();
    jmeter.configure(testPlanTree);
    jmeter.run();
}

Any help is highly appreciated.

Best regards, Jan

1

1 Answers

1
votes

I ran into the exact same issue. There is a separate jar artifact which contains a couple of Functions such as org.apache.jmeter.functions.Property2. You need to make sure that those get registered properly.

Using maven I added this to my pom:

<dependency>
    <groupId>org.apache.jmeter</groupId>
    <artifactId>ApacheJMeter_functions</artifactId>
    <version>${jmeter.version}</version>
</dependency>

Now, tell JMeter to search for additional components within it

JMeterUtils.setProperty("search_paths", "ApacheJMeter_functions-2.13.jar");

The string you add to the search path needs to match the artifact as it is found on the classpath. So, when launched from eclipse that is the path to the artifact within your maven repository.