Jmeter variables value is not getting set after each loop - jmeter

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:

Related

JMeter use variable array values individually

I am struggling a bit to make use of a variable created using the Json extractor, I have extracted all the ID's from a response and want to cycle through them individually across the threads.
Thread 1 would use id_1 and thread 2 would use id_2 etc.
I have tried using a ForEach controller but it's cycling through the whole set for each thread.
Test runs like this:
Generate access token
Get parameters - Extract the list of ID's here.
Update parameter - Pass the ID individually here per thread.
Is there a way to achieve this?
You won't be able to do this because as per documentation:
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
So if you want to perform extraction using one thread and then hit everything using multiple threads you can either convert all the variables which start with id_ to JMeter Properties using the following Groovy code snippet:
vars.entrySet().each { variable ->
if (variable.getKey().startsWith('id_')) {
props.put(variable.getKey(), variable.getValue())
}
}
and then you will be able to access the properties using __P() function like:
${__P(id_${__threadNum},)}

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.

How do I use a JMeter Variable declared in an extractor in a User Defined Variable config

I have an http request that uses an extractor to set a JMeter variable (lets call it test) from the body. When I look at the debug controller I can see this works fine. Next I want to append something to the beginning of the variable so I add a user defined variable node and add a variable with the name new and I set the value to ${test}. However when I look in the debug response I see ${test} instead of the value.
I tried the same thing setting the value manually in 2 different UDV nodes and it works fine, so how do I append to a JMeter variable declared in an extractor?
As per JMeter Documentation:
The User Defined Variables element lets you define an initial set of variables, just as in the Test Plan.
Note that all the UDV elements in a test plan - no matter where they are - are processed at the start.
So the User Defined Variables element will be read only once and only when the Test Plan is started.
If you need to overwrite the current variable with a new value you can go for i.e. __groovy() function, the relevant syntax would be something like:
${__groovy(vars.put('foo'\, 'some_prefix_' + vars.get('foo')),)}
Demo:
vars is a shorthand for JMeterVariables class instance, it provides read-write access to all JMeter Variables in the current thread scope. Check out The Groovy Templates Cheat Sheet for JMeter to learn what else you can do with Groovy scripting in JMeter tests
UDVs can't be used in dynamic way because they are process once at the start of the test.
Don't use UDV, use JSR223 Sampler (or PostProcessor) with vars;
vars.put("new", "prefix"+ vars.get("test"))
Another option is to use Set Variables Action plugin

Fetch the value of variable inside variable in jmeter

In the JSR Sampler I am assigning the value of a String I create i.e., SFDC_Prouct_1 in list. for e.g.,
list=SFDCProduct_5
Here SFDCProduct_5 is already a variable which has XML elements. Now I am trying to place a http request and in the payload I want to inject the value of SFDCProduct_5 . But I have to write ${list}, as list has the value of SFDCProduct_5 .
I tried ${${list}}, but thats not working.
Any ideas?
In JSR223 Sampler you can get the nested variable using vars.get
vars.get(vars.get("list"));
If I correctly understood your question you need to wrap your ${list} into __eval() function like
${__eval(${list})}
Demo:
See Here’s What to Do to Combine Multiple JMeter Variables article for more information if needed.

Resources