I want to use All extracted values in a loop controller - jmeter

I have written a regular expression inorder to get all the values. Now i have all the values. I want to use the extracted values in a sampler under a loop controller and every hit it has to pic dynamic value.
This will have the dynamic values around 78
I want to Iterate 78 times
Every hit this has to pic unique data
Please help me as i am stuck here to complete the script.

The most suitable test element is ForEach Controller
Given the following variables defined:
Just add a ForEach Controller and configure it as follows:
That's it, you should be able to access each and every match as ${someVar} where required
check out Using Regular Expressions in JMeter article for example use case
If you want to keep the current setup with the Loop Controller - you can refer each and every variable using __V() and __intSum() functions combination like:
${__V(_Webp_${__intSum(${__jm__Loop Controller__idx},1,)},)}

Related

Variable value not updated in each iteration in Jmeter

I am using timestamp as a value in my script to keep it unique and distinguishable in each of the iterations. I am using ${__time(/1)} function and storing it in the user defined variable inside a transaction controller and later using same variable in other transactions and json payload as well. This works well for single iteration.
I expected that in each iteration timestamp will be updated. but I can see that in each iteration same timestamp is being used. How could I make it updating timestamp in every iteration as I need to use only one timestamp value in an iteration and not repeating in successive iterations.
The User-Defined Variable config element is processed only once at the start. It is processed after the test plan. It is not suitable for your use case.
UDVs should not be used with functions that generate different results each time they are called. Only the result of the first function call will be saved in the variable.
There could be a number of options.
Using User Parameters Pre-processor
You may set the Update Once Per Iteration to suit your requirement.
Using Set Variables Action plugin
Set the value in JSR223 Pre-processor
You may place the controller below the Test Plan.
As per User Defined Variables documentation:
Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.
So the variable is evaluated only once, when the test starts, if you want it to return you the current timestamp each time it's called - just use __time() function directly where required, there is no need to declare it as the variable.
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
I also don't think that /1 bit in your ${__time(/1)} function does anything meaningful, maybe it worth considering removing it completely
Adding value to a variable will save time only once on load, you can put the time function inside payload to get different times
Another option is to use pre processor as User Parameters over User Defined Variables
For defining variables during a test run, see User Parameters. UDVs are processed in the order they appear in the Plan, from top to bottom

jmeter - Looping based on DB query - use db data as variables

Based on this thread: jmeter - Looping based on DB query, i managed to get counter to the Loop controller, and and working fine.
Now i need updated version, where DB query returns 2 variables, so i can use them as parameters for the call.
url secret
https://test1.com/ 1234
https://test2.com/ 1234
https://test3.com/ 1234
And to be able to use them in:
As:
But, when i tried to use them as: ${url_#}, ${key_#} test is not working.
Is there other any way how can i use those 2 variables fetched from DB query, and the looping logic to be respected?
Any help is appreciated!
You need to use the following test elements combination:
${__jm__Loop Controller__idx} pre-defined variable to get the current Loop Controller's iteration number
__intSum() function to add 1 to the iteration number (it's zero-based)
__V() function to put everything together
The combination would be:
${__V(url_${__intSum(${__jm__Loop Controller__idx},1,)},)}
Demo:
More information: Here’s What to Do to Combine Multiple JMeter Variables
I found my answer. what help me was: ${__V(url_${__counter(,)})} variable together with counter function.

Jmeter variables value is not getting set after each loop

I am using the loop controller to loop an array & give HTTP request for each value. But in some cases, variable values are set with current value from the array
It might be the case the array simply doesn't have the variable matching the current loop index, double check the JMeter Variables which are in scope for each loop using Debug Sampler and View Results Tree listener combination.
I cannot reproduce your issue using the following simple setup:
JMeter Variables defined:
The variables referenced using __V() and __intSum() functions combination like:
${__V(var_${__intSum(${__jm__Loop Controller__idx},1,)})}
See Here’s What to Do to Combine Multiple JMeter Variables for the clarification of the syntax used.
If you just need to iterate JMeter Variables it might be easier to go for the ForEach Controller:

How can i generate dynamic sequence number of transaction controller

Usecase :- I have one thread group. Inside this i have one loop controller. In loop controller i have 120 transaction controller. During debugging of the script it creates confusion to find the failed steps. I want to put some variable for dynamic number generation. I did it by using Beanshell Sampler as following:
After this i used beanshell function ${__BeanShell(Integer.parseInt(vars.get("POC_Step_Number"))+1,POC_Step_Number)} inside the name of transaction controller. It works for me.
I want to use variable name in place of Beanshell function ${__BeanShell(Integer.parseInt(vars.get("POC_Step_Number"))+1,POC_Step_Number)} function. How can i do that?
You can use loop controller index (add +1 if you want to start with 1)
${__groovy(${__jm__Loop Controller__idx}+1)}
JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named LC, then you can access the looping index through ${__jm__LC__idx}. Index starts at 0

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