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.
Related
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:
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,)},)}
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
I have a JDBC request to fetch row count - 'rownum' of a table. Now I need to do some additional SQL operations in separate JDBC request in which I need to extract data of only 2 rows at a time which I am able to handle using counter. Now I need to decrease the rownum by 2 as I have already used two rows of the table. So I am trying to use while loop in which I would have while rownum>0. But I . have no idea how to use the output variable of first JDBC request which will hold the integer value in while loop. I also need to subtract 2 from this in every iteration.
The output variable name of first JDBC request is "count_num"
Then I used beanshell to parse this as integer using following code:
int i = Integer.parseInt(vars.get("{count_num}").trim());
This beanshell sampler is also failing. I even tried using vars.get("count_num"), but that also failed stating ::
Error invoking bsh method: eval Sourced file: inline evaluation of: ``int i = Integer.parseInt(vars.get("count_dcn").trim());'' : Typed variable declaration
Now in my while loop, I want to use this value of I (no idea how to do it, should I be using ${i}).
I also need to subtract 2 from the value of I probably at the end of while loop (after second forEach controller maybe), again not sure how to do it.
Structure of Test Plan:
${__javaScript(parseInt(${count_dcn_1})>0)}
this code worked
I creating script which let me to get values from database.
Now, when I'm executing query oracle returning me too many values.
My query looks like that : select * FROM OFFERS
I'm getting:
OFFER_NR_#=101042
OFFER_NR_1=0001G000210
OFFER_NR_10=0001G000411
and many many more...
I want to take exactly one value e.g. OFFER_NR and use it in request
------- request SEARCH_OFFER ${OFFER_NR} = 101042
During next course loop I want to take another value as variable
------- request SEARCH_OFFER ${OFFER_NR} = 0001G000210
It's just like using CSV FILE CONFIGURATION, which can give me exactly each next row for every thread group iteration, but I don't know how can I do this the same using jdbc request.
1 You need to use ForEach Controller configured as follows:
Input Variable Prefix: OFFER_NR
Output Variable Name: anything meaningful, i.e. CURRENT_OFFER
Check `Add "_" before number" box
Place your 2nd request under the ForEach Contoller
Refer each subsequent OFFER_NR as ${CURRENT_OFFER} where required
See Debugging JDBC Sampler Results in JMeter guide for more detailed explanation of your and other situations