JMeter Http request not working as expected in loop controller - jmeter

When i use a loop controller to go through my results from regex extractor, it stops working when i include a http request inside the loop controller.
Regex extractor format (will output multiple results with multiple groups each)
name of created variable - pageDetails
Template: blank
Match no -1
After that i initialized a loop controller (with a counter) to go through all the results of this regex
The counter is as follows
Starting value =1
Increment =1
Maximum value =${pageDetails_matchNr}
Reference Name =pageDetailsIndex
I have a debug sampler in the loop thats using the counter
${__evalVar(pageDetails_${pageDetailsIndex}_g1)} ${__evalVar(pageDetails_${pageDetailsIndex}_g2)}
Also have http request in the loop thats using the counter
If i disable the httprequest in the loop controller, the debug sampler works, and prints out all the values
However, if i enable the http request, BOTH the debug sampler and http request only work in the first iteration works i.e. when ${pageDetailsIndex} = 1. When its above 1 then ${__evalVar(pageDetails_${pageDetailsIndex}_g1)} etc. all return blanks...

Most probably your Regular Expression Extractor scope is not correct, if you want to apply it to one Sampler only - you need to make it a child of that particular sampler
From your explanation it seems that the HTTP Request sampler which is under the Loop Controller is overwriting the previous values which should not be the case.
Also be aware that your Counter is not necessary, there is ${__jm__Loop Controller__idx} special JMeter Variable which holds the value of the current iteration of the Loop Controller.

Related

Can a request parameter extracted from response of previous request have different values when run multiple times - Jmeter

Scenario:
We are extracting a value from 1st request and passing it as a parameter for the 2nd request.
The 2nd request is in Loop controller and it is run multiple times, But every time the 2nd request runs , It should take different value. Is there any way to do this.
Eg: Below is the example screenshots for the same. data is the variable which is passed to the second request .When second request is hit multiple times , It should extract different values.
In the Regular Expression Extractor set "Match No" to -1 to you will extract all the matches into:
data_1=1
data_2=2
etc.
In the Loop Controller set the "Loop Count" to ${data_matchNr}. This way the controller will iterate as many times as there are matches in the Regular Expression Extractor
Instead of ${data} use ${__V(data_${__intSum(${__jm__Loop Controller__idx},1,)},)}
More information: Here’s What to Do to Combine Multiple JMeter Variables

JMeter waitfor page to load fully

is it possible to wait for XPath or CSS selector to display in Jmeter?
I am using HTTP request to send API call and I have assertion as CSS selector path but due to API slowness , I would like to implement a waitfor method for the specific element in UI.
JMeter doesn't execute any Post-Processors or Assertions or Listeners until it gets response from the server therefore you don't need to do anything. See Execution order user manual chapter for more details.
However if I misunderstood your requirement and you want to repeat a HTTP request until XPath or CSS extractor return the value you're looking for you can put the request under the While Controller and put the condition of your choice there:
In the above case:
On iteration 0 of the While Controller ${myVariable} doesn't have any value (CSS Selector Extractor hasn't been executed yet)
Iterations from 1 to 5 - ${myVariable} has value of foo which doesn't match While Controller's condition so it loops over
Iteration 6 - ${myVariable} value becomes bar and the While Controller exits the loop.
Just in case, textual representation of the jexl3() function used to compare variable with some value:
${__jexl3("${myVariable}" != "bar",)}

Fill an arraylist with repeated HTTP Request's Response Data on Jmeter

I need to process a specific URL (that returns different numbers each time) and get its return into an array to use it in another HTTP Request.
My test is built like this:
Loop Controller (2 loops)
HTTP Request
JSON Extractor
Reference Name: myVar
Match No.: -1
Compute concatenation var: checked
Debug Sampler
When this block is executed, when I check the Debug Sampler's Response Data, it always fills the variable myVar with the last occurrence, like this:
myVar_1=
myVar_1_g=0
myVar_1_g0=3154
myVar_matchNr=1
Shouldn't it also store something like myVar_2, since I defined the "Match No.:" as **-1 **?
I read some answers as this one and this but my problem is that I need to iterate a variable with some response data, no matter how many times it is executed.
The reason is that on each iteration of the Loop Controller your myVar variable gets overwritten
If you want to store myVar variable value for each loop you should amend its reference name to look like:
myVar${__jm__Loop Controller__idx}
Then given you have 2 iterations of the Loop Controller you will have the following variables defined when the loop ends:
myVar0=xxxx
myVar1=yyyy
The ${__jm__Loop Controller__idx} variable is available since JMeter 4.0

Looping in Jmeter

Looping test occurrence based on the data count retrieved from the JDBC request and also as input data for the HTTP request
I have test scenario where i need to use the DB output as the input criteria for the HTTP request. Based on the DB output count( from the first request) i need to loop the HTTP request and it data accordingly
I tried the logical Loop Count by passing the count variable from run time as ${TEST_ID_#}, still its not working.
I tried the logical Loop Count by passing the count variable from run time as ${TEST_ID_#}, still its not working.
Debug Sampler Output
You can extract the counter using Post Processor [either Regular Expression Extractor or JSON Extractor etc.]
Once you have extracted that count, now place a Loop controller as a parent of HTTP request.
For example. I am using User Defined Variable for loop Count:
Any reason for using ${TEST_ID_#} variable? If your Debug Sampler screenshot is full and correct you should be using ${KEY_ID_#} instead.
Also it might be a better idea to use ForEach Controller instead of the Loop Controller, the relevant configuration would be something like:
References:
How to Use ForEach Controller in JMeter
Using Regular Expressions in JMeter

How to use JMeter's while loop to validate a value from a Sampler which need to be executed again?

I am doing performance validation of HTTP requests. I have a request which returns JSON values in which, a key's value contains 'Planned' or 'Processing' or 'Completed'.
In first, it returns 'Planned', then it returns 'Processing' and finally it returns 'Completed'.
I use Regex extractor to that particular key's value.
I want to repeat that Sampler until it returns 'Completed'.
Please help me to achieve this using while loop or whatever possible.
Edit: After 100's of attempts only (few mins), the sampler returns 'Completed' until then, it returns 'Processing'.
#Bala
You can implement this using While loop
You have to hit the http request first and extract the Status..
now in the while loop use this Jmeter function to evaluate the status ${__javaScript("${Status}" != "Completed")}
Extract the status again in the loop
Here is the TestPlan

Resources