In JMeter I am exporting a list of properties from one thread group to another.
They look like:
prop_1="value1"
prop_2="value2"
prop_3="value3"
prop_4="value4"
prop_#="4"
Now in the 2nd thread group I want to loop over them - I tried to do that with a foreach controller. However the foreach controller expects a variable prefix and not a property prefix. Is there any way to solve this? One way would probably be to copy all the properties into variables in a preprocessor, but that sounds very clumsy.
Background: My first thread group triggers several job execution of a longer duration. The second thread group shall poll a database until each of those jobs are finished. For that it needs to know the job names that were created by the initial thread group (in my example above "value1..4"). Is there any nicer way to transfer the job names from one thread group to another than using properties?
Indeed, looking into ForEach Controller source it appears that ForEach Controller is looking only in JMeter Variables.
final JMeterVariables variables = context.getVariables();
final Object currentVariable = variables.getObject(inputVariable);
if (currentVariable != null) {
variables.putObject(getReturnVal(), currentVariable);
if (log.isDebugEnabled()) {
log.debug("ForEach resultstring isDone=" + variables.get(getReturnVal()));
}
return false;
}
However it is possible to convert JMeter Properties to JMeter Variables using Beanshell scripting.
For instance, if you need to convert all JMeter Properties starting with prop_ into JMeter Variables with the same name, add a Beanshell Sampler before your ForEach Controller and put the following code into it's "Script" area:
Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String propertyName = e.nextElement().toString();
if (propertyName.startsWith("prop_")) {
vars.put(propertyName, props.getProperty(propertyName));
}
}
Above code will iterate all the JMeter Properties, look for the ones starting with prop_ and convert them to JMeter Variables which you can use in the ForEach Controller.
For more information on Beanshell scripting in Apache JMeter refer to How to use BeanShell: JMeter's favorite built-in component guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With