3

I need to share few variables between two thread groups in an Apache jmeter project. I found that variables cannot be shared between thread groups and I have to use properties. I have written the below script inside a JSR223 PreProcessor in the first thread group to set the property values. It runs without any exception.

@Grab('org.yaml:snakeyaml:1.17')

import org.yaml.snakeyaml.Yaml;
import org.apache.jmeter.services.FileServer;

String baseDir = FileServer.getFileServer().getBaseDir()

Yaml ymlparser = new Yaml()

Map config = ymlparser.load((baseDir+"/config/tool.yaml" as File).text)

String base_path = baseDir + "/data/" + trafficConfig.find{it.key=="name"}?.value

${__setProperty(basePath, base_path)};

If I log the value of the property 'basePath' from the same JSR223 PreProcessor, it will return the correct value.

Then I'm reading the property value from a JSR223 PreProcessor in the second thread group like below.

${__property(basePath, base_path)}
log.info( base_path );

It will through the below exception in jmeter log.

2019-11-02 18:54:19,353 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: basePath for class: Script470 at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:162) ~[groovy-all-2.4.16.jar:2.4.16] at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) ~[?:1.8.0_221] at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:225) ~[ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:44) [ApacheJMeter_components.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:935) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:537) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.1.1 r1855137] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_221]

1
  • I'm using apache jmeter version 5.1.1 and I have added apache ivy-2.5.0.jar file to the lib. Commented Nov 3, 2019 at 3:17

1 Answer 1

2

Use props to set property

props.put("basePath", base_path);

Don't use ${} syntax in JSR223 components

Sign up to request clarification or add additional context in comments.

1 Comment

And I should retrieve property basePath using props.get("basePath"). That worked. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.