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]