Monday, July 11, 2011

Looping through all output of a RegExp extractor (without the for each controller)

I forget why the user couldnt use a For Each controller , but heres how to loop through the result of a Regex Post Processor that returns multiple values

ThreadGroup
+HttpSampler
++Regex Extractor (variableName = links)
+WhileController(${__javaScript(${C} < ${links_matchNr})})
++HTTPSampler use ${__V(links_${C})} to access the current result
++Counter (start=1,increment=1,maximum=${links_matchNr},referenceName=C)

8 comments:

Anonymous said...
This comment has been removed by the author.
Anonymous said...

I am a beginner, this is the exactly the issue I am trying to deal with. I used regX to parse my response array where ids_matchNr = 63. I followed your instruction to loop the next http request sample, using the previously parsed ids from regX but the loop does not repeat. Can you please help me? Thank you

Deepak Shetty said...

why not use a foreach controller?

In most cases check jmeter.log for errors and add some debug samplers and view results tree listener so you can check the values of the variables to diagnose the issue

Anonymous said...

Sorry I am new to JMeter. Can you please tell me how to increment the foreachloop count to use the multiple variables extracted by the regX. Thank you

Deepak Shetty said...

The for each controller doesnt need you to have any counter
Say if your regex output variable is extractedVariable (which has many values) Then just Use
ForEachController and in input variable prefix use extractedVariable (same name as you specified in the regex extractor)
and in output variable name use any value (you will refer to this value)

so
HTTPSampler1
+Regex (var = extractedVaribale)
ForEach (input=extractedVariable, output=currentValue)
+HTTPSampler2 (use ${currentValue})

This will execute HTTPSampler2 as many times as you have the value and ${currentValue} will be the value inside the loop (value1,value2,value3 etc)

Use Debug Sampler + View Results Tree if something is not working to diagnose issue
and refer to
http://jmeter.apache.org/usermanual/component_reference.html#ForEach_Controller

Anonymous said...

works like a charm! thank you!

sonu mahajan said...

i am having 2 variables that are extracted from Regex, and both need to be passed onto the following request into loop,
so can u help me out how to go with 2 dynamic variables.

sonu mahajan said...

I have a page where search results are there in a list and need to extract these list value till 10 numbers and pass it to the following requests in a loop using 2 dynamic values in each request.