How can i generate dynamic sequence number of transaction controller - jmeter

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

Related

Jmeter - How to provide variable from array to JDBC request (inside the loop controller)

Based on this thread Jmeter - Use Loop controller based on array (created from from multiple variables) I managed to use Loop controller based on the array.
Now I need to pass the each value from the array into JDBC, so I can perform select statement based on every single member of the array.
What I try is:
But I got error as:
When I try the same statement with Dammy sampler is working fine.
How to pass member from the array into JDBC inside the loop controller?
JMeter log file explicitly states Cannot invoke method length() on null object
The only place where you're invoking length() function is vars.get('array').length() which means that your ${array} variable is null (not defined), you can double check it using Debug Sampler and View Results Tree listener combination.
If the same statement works elsewhere - the only explanation I can think of is variable scope, see JMeter Scoping Rules user manual chapter for more details.

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.

I want to use All extracted values in a loop 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,)},)}

How to display actual loop count in JMeter

We can display the actual thread by:
${__threadNum}
Is there something similar for the actual loop count?
You can use ${__jm__Thread Group__idx} to get current loop iteration
${__jm__Thread Group__idx}
Notice this is part of a general enhancement in JMeter 5 for exposing the loop count
While Controller now exports a variable containing its current index named __jm__<Name of your element>__idx. So for example, if your While Controller is named WC, then you can access the looping index through ${__jm__WC__idx}

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