I have a JMeter test with 2 Thread Groups - the first is a single thread (which creates some inventory) and the second has multiple threads (which purchase all the inventory
Well this is one way to do it; follow these steps and it will work, later you can adjust it to your needs! Variables are not shared among threads (JMeter calls this a feature probably :) ). But properties are! So set your variable as a propery like so:
1) Click your testplan and enable 'Run Thread Groups consecutively' -> this makes the thread groups run ordered and not randomly. (you can later adjust it, but for now to get it to work..)
2) create a threadgroup called 'setup' for instance; in that thread group add a BeanShell Sampler with the following code:
import org.apache.jmeter.util.JMeterUtils;
JMeterUtils.setProperty("theNameOfYourNewProperty", "theValueOfYourPropery");
So now the property has been set! If the value you want to store as a propery is a variable allready (User definded variable or reqex variable for instance) you can do:
JMeterUtils.setProperty("theNameOfYourNewProperty", vars.get("theNameOfYourVariable"));
3) add a testgroup 'actual test' for instance with a number of threads higher than 1; add a test and to that test add a BeanShell Preprocessor with the following code:
import org.apache.jmeter.util.JMeterUtils;
vars.put("theNameOfYourNewProperty", JMeterUtils.getProperty("theNameOfYourNewProperty"));
So now you've created a variable in that thread called theNameOfYourNewProperty which has the value of your system property theNameOfYourNewProperty. In your test you can now access it like:
${theNameOfYourNewProperty}
And it will work for each thread, not only just the first thread..