in my jmeter test I have a loop controller which works on messages got from previous thread group with a while loop inside. In while I'm sending GET as long as it is not successful. I would like to know how many of GETs was send. It looks like this:
-Loop Controller
--While (${__javaScript("${statusCode}"!="200")})
----Counter (on retry variable)
----GET ${retry}
I thought that every while loop will have an individual counter, but it's not. The counter gets incremented in every Loop Controller iteration. Any ideas?
It looks like that you need __counter() function instead of Counter Config Element. It's incremented by one on call, not on iteration.
Related
In the below snapshot if select category response assertion fails, how do i goto loop controller and continue the loop.. until the mentioned required no.of count in loop controller
I don't think it's possible with the Loop Controller, the maximum you could do is:
Check whether previous Sampler is successful or not using If Controller and JMeterThread.last_sample_ok pre-defined variable
Add Flow Control Action sampler as a child of the If Controller and configure it to "Go to next iteration of Current Loop"
However this way you cannot avoid incrementing the count of the Loop Controller and if/when you run out of iterations JMeter will exit the loop (unless it's something you're looking for), this way you can only skip Samplers which are below the failing one in the Loop Controller.
Maybe it worth considering going for the While Controller instead.
I have created a loop in Jmeter and I have a counter within the loop.
vars.put("counter", "5")
I am then incrementing the loop by +5 for every iteration of the loop. What I am trying to do is add that counter to this:
${__timeShift(HH:mm:ss,,PT5M,,)}
So I am trying to dynamically add 5 minutes to the TimeShift each iteration. so something like ${__timeShift(HH:mm:ss,,PT${counter}M,,)}. I know this is wrong but I can't think of a way to do it. Does anyone have any ideas?
This guy: ${__timeShift(HH:mm:ss,,PT${counter}M,,)} should work just fine, most probably the problem is with the way you're incrementing the counter.
Instead of scripting you can consider switching to Counter configuration element:
So you would be able to get something like:
If you want to continue with scripting be aware of vars.putObject() function which allows you storing any arbitrary object into JMeter Variables so you won't have to convert it from String to Integer and vice versa
I Have 5 HTTP request in single thread, I want to run first request multiple times and then other request only single time
I can't use multiple thread as all request are depends on each other.
Depending on what you're trying to achieve:
Put the request which needs to be run only once under Once Only Controller, this way the Sampler will be executed only during first iteration of the Thread Group
If you want more complex/flexible criteria - put the request which needs to be executed only once under the If Controller, this way you will be able to specify whatever criteria you want. For example if you want to run a Sampler only during 5th iteration use the following condition:
${__jexl3("${__jm__Thread Group__idx}" == "5",)}
this way the sampler(s) which is (are) under the If Controller will be executed only if the condition is met:
Put first request under Loop Controller with Loop Count as the times you want to repeat
JMeter will loop through them a certain number of times, in addition to the loop value you specified for the Thread Group. For example, if you add one HTTP Request to a Loop Controller with a loop count of two, and configure the Thread Group loop count to three, JMeter will send a total of 2 * 3 = 6 HTTP Requests.
Choose request(s) you want to execute multiple times and then:
Right Click -> Insert Parent -> Logic Controller -> Loop Controller
Example:
Thread: 50,
Ramp-Period: 0,
Loop: 1.
I have to send different value with each thread. Is it possible to do it without changing the loop count?.
If you need to add something to an existing variable it may be done via __intSum() function
__counter() function generates incremented number each time it's being called either per-thread or global
Another candidate is __threadNum() function which is basically the number of current thread.
See How to Use JMeter Functions posts series for advanced information on above and other useful functions.
Your question looks like this - jmeter unique id per thread for http request
You can also use Beanshell to create an unique ID for every thread.
You can achieve this by adding a counter under the thread group.
In the counter it's possible to set the start, increase and maximum number you want to reach.
Then add reference name in counter, which will be used in your request as ${reference_name}
My test plan is below
!TestPlan
ThreadGroup
LoopController1
Sampler1
BeanShellPostProcessor
Listener
LoopController2
Sampler2
As part of Beanshellpostprocessor, i am putting count value to a variable
props.put("noOfRecords",vars.get("msg_#"));
Now this value i am placing on 2nd loopcontroller as ${__P(noOfRecords,0)}
This setup is failing for iterations where we don't have any records. So the previous "${__P(noOfRecords,0)}" value is considered while running the Loop2.
Is there any other way we can achieve the dynamic loop counter?
You can use variables or properties in the Loop Controller to change the loop count at run time.
If the Property/Variable is set correctly by the Beanshell postprocessor in your test, It should work. That is, you need to set the value to 0 explicitly when there is no record. Otherwise Properties (which are not destroyed until you close JMeter) might use the previous value.