2

TestPlan Thread Group HTTP Request1 ->Regular Expression Extractor - Return 10 Results - URLs -- Single Thread ForEach Controller - Using variable from extractor - Successfully Loops through above results HTTP Request2 ->Regular Expression Extractor - Return 10 Results This above is under 1 thread

I want to have ForEach Controller under different thread --run multiple therads and use the URLs extracted from 1 thread HTTP Sampler -- I tried to use these two approaches https://www.blazemeter.com/blog/knit-one-pearl-two-how-use-variables-different-thread-groups How do I pass a variable from one Thread Group to another in JMeter but somehow now managed it to work Please help

Stefan
  • 17,448
  • 11
  • 60
  • 79
Sandeep Sharma
  • 109
  • 2
  • 15

1 Answers1

0

ForEach Controller will not work with JMeter Properties, it is designed to work only with JMeter Variables so if you want to pass them between different Thread Groups you will need to do some scripting.

  1. Add JSR223 PostProcessor after the Regular Expression Extractor and put the following code into "Script" area

    vars.entrySet().each { var ->
        if (var.getKey().startsWith('foo')) {
            props.put(var.getKey(), var.getValue())
        }
    }
    

    replace foo with what you have as a Reference Name in the Regular Expression Extractor. The above code will convert all variables which names start with foo into the relevant JMeter Properties

  2. Add Test Action sampler to the second Thread Group (you don't need to measure time of properties to variables conversion, do you)
  3. Add JSR223 PreProcessor as a child of the Test Action sampler
  4. Put the following code into "Script" area

    props.entrySet().each {prop ->
        if (prop.getKey().startsWith('foo')){
            vars.put(prop.getKey(),prop.getValue())
        }
    }
    

    the above code convert JMeter Properties into JMeter Variables so you will be able to use them in the ForEach Controller in the second Thread Group. Again, replace this foo with the reference name of your own variable.

See Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter tests

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • i have reference name:inputKitchenLevel1 – Sandeep Sharma Dec 14 '17 at 20:51
  • i have reference name:inputKitchenLevel1. In JSR223 PostProcessor i have this code vars.entrySet().each { var -> if (var.getKey().startsWith('input')) { props.put(var.getKey(), var.getValue()) } } language is selected as groovy - 2nd thread Test Action -> JSR223 PreProcessor with code props.entrySet().each {prop -> if (prop.getKey().startsWith('input')){ vars.put(prop.getKey(),prop.getValue()) } } foreach controller - input variable prefix : ${inputKitchenLevel1} but I am getting an error – Sandeep Sharma Dec 14 '17 at 20:58
  • error at the JSR223 PostProcessor ERROR javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158) ~[groovy-all-2.4.12.jar:2.4.12] at javax.script.AbstractScriptEngine.eval(Unknown Source) ~[?:1.8.0_144] at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:42) [ApacheJMeter_components.jar:3.3 r1808647] at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:833) [ApacheJMeter_core.jar:3.3 r1808647] – Sandeep Sharma Dec 14 '17 at 21:00