Can a request parameter extracted from response of previous request have different values when run multiple times - Jmeter - 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

Related

Jmeter - My response has multiple values of same id. I want to extract and pass these values incrementally to the next request

My response to a save action is somewhat like this-
"diagnosisId":45686,"confidence":0.0, --other text--
"diagnosisId":45966,"confidence":0.0,--other text-- etc. Say there are 27 diagnosis Ids.
Now i want to send request for the 1st Diagnosis Id in loop till the last id (multiple records/rows to save depending upon the diagnosis Ids).
Request is something like this -
"diagnosisId":45686,"confidence":0," etc.
I have extracted the Diagnosis Id using Regular Expression extractor and matched the first value -
"diagnosisId":(.+?),
How do I pass the values incrementally now?
Given you provide "Match No:" as -1 in the Regular Expression Extractor:
You will get the following JMeter Variables as the result (viewable via Debug Sampler):
At this stage you can add ForEach Controller and configure it like:
Input variable prefix: diagnosisId
Output variable name: anything meaningful, i.e. id
That's it, you can reference each consecutive ID as ${id} in the request(s) which will be the children of the ForEach Controller:
Another example: Using Regular Expressions in JMeter

JMeter Http request not working as expected in loop controller

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.

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 capture dynamics values which will be generated from loop in JMeter

I have one scenario to test in which one transaction needs to be iterated for several times and then submit the request. For each iteration, I will get one detID (e.g: for 20 iterations - 20 unique detID). The problem is while submitting the request all the detID are been passing in the request parameters (example: if loop ran for 10 iterations then 10 detID are passing inside the request). I have put regular expression extractor to the transaction which is in loop which will capture all the mathces but it is capturing only the last one. (e.g: if loop ran for 10 iteration, regex capturing the 10th iteration value).
Please help me.I want to include these detID inside the submit request.
Add a Counter before the request with the regex.
Add a BeanShell PostProcessor as a child of the request after the regex with the below code:
String ID = vars.get("ID");// ID is the reference name of your regex
String Counter = vars.get("Counter");// Counter is the reference name of your regex
vars.put("ID_"+ Counter, ID);
You will have 20 different variables each one holds a different ID value and you can use them as ${ID_1} for the first ID and ${ID_2} for the second and so on.

JMeter: Can't copy CSV variable into another variable

I am reading a token from a .csv file into variable CSV_ACCESS_TOKEN. I have 3 request under one ThreadGroup. I want a scenario when logged in user loads a page thrice (or N time). So 1 thread is looping N time. After reading token once, I dont want to read next token in loop but want to loop through URL three (or N) time with same token.
Right now I am reading data from CSV, and using "BeanShell Sampler" inside "Once only Controller". In the sample I am using line like: vars.put("ACCESS_TOKEN",vars.get("CSV_ACCESS_TOKEN"). But that BeanShell sampler is recorded in my Summary Result. I don't want that.
I tried using "User Defined Variable" controller and try to assign the value ${__evalVar(CSV_ACCESS_TOKEN)} but it return empty value for ${ACCESS_TOKEN}. When I use ${CSV_ACCESS_TOKEN}, it shows me the values. If I use some other variable instead of CSV_ACCESS_TOKEN in UDV controller, it assigns the value from other variable and I see values for ${ACCESS_TOKEN}.
Why CSV variable is not assigning the values in regular variable.
Thanks
Vinay
If you have 3 requests, I suggest you put a Beanshell preprocessor on the first request, which copies the CSV_ACCESS_TOKEN to ACCESS_TOKEN.
Each of your samples can the use ACCESS_TOKEN, so CSV is accessed once per cycle of 3.
Each time the preprocessor run (ie before each 1st request), CSV_ACCESS_TOKEN will get updated from the dataset.
If it is the same request, which you do not wish to duplicate, you can look into use of test fragments and modules, so you can run the same sample from a variety of controllers. First from a simple controller with the preprocessor attached, and then from a loop controller to perform 2 more requests.
I think the code you have used already to manipulate the CSV values will continue to work in this scenario.

Resources