JMeter - repeatedly run a While Controller - jmeter

Goal:
I would like to visit 10 different URLs of the form http:localhost/path/item/${id} where id is a Random Variable. For each of these URLs, I want to request them until the response returns a specified string.
Current setup:
I have a While Controller with an Http Request under it. The condition looks like ${__javaScript('${response}'.indexOf("my string") == -1,)} (the response variable is saved via a JSON Extractor). I also have the Loop Count in the Thread Group set to 10.
Problem:
My test plan works fine, but only for one URL. It's as if it's ignoring the Loop Count setting. Assuming the While Controller makes two requests per URL, it's only making two requests total, rather than expected 20.
This is puzzling because if I use a Loop Controller with a Loop Count of 5, it makes 50 total requests.
How can I achieve the desired behavior?

Cannot be 100% sure without seeing the whole plan, but I suspect it's because you are not unsetting ${response} for next iteration, after it reaches true condition. I.e.
First iteration starts, and ${response} is empty/undefined ==> enters while
At some iteration within while it sets ${response} so, that ${__javaScript('${response}'.indexOf("my string") == -1,)} gives true ==> While exits
Next iteration starts. If at this point ${response} is still the same as in previous iteration, it will never enter while, since it's already true.
If this is the case, reset value at the beginning of iteration.
To reset the value, add a BeanShell Sampler nd either remove a variable:
vars.remove("response");
or set its value to empty / something else:
vars.put("response", "");
If this is not the problem, look for exceptions in the jmeter.log. Could be that your script is exiting due to error.

Related

JMETER - How can I pass 2 condition in a while loop on Jmeter

How can I pass 2 condition in a while loop on Jmeter. The conditions are
The request should run in loop till "Pass" response comes.
While loop should run only for 1 minute.
Condition 1 is working fine. However condition 2 is unable to implement.
I have tried running the While Loop inside a Runtime Controller. But the issue is, if the response "Pass" comes before 1 min, the rest of the test stops.
Tried other way round (Runtime inside While Loop) leading to numerous execution of the request, even after receiving "Pass" response.
Will appreciate any leads on this. Thanks
Add a JSR223 Sampler just before the While Controller and store the current time into a JMeter Variable using the following code:
SampleResult.setIgnore()
vars.putObject('whileLoopStart', System.currentTimeMillis())
Use the following __groovy() function as the While Controller's condition:
${__groovy(!vars.get('your_variable').equals('Pass') && ((System.currentTimeMillis() - vars.getObject('whileLoopStart')) < 60000),)}
This way the While Controller will run until:
either your_variable is not equal to Pass
or 60 seconds pass
whatever comes the first
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
This could be another solution.
You can achieve the desired outcome with the following components.
Runtime Controller
If Controller
Flow Control Action
Set the Runtime (duration) in the Runtime Controller
Set the first condition you already have in While Controller in the If Controller
Click the Break Current Loop to exist from the Run Time controller

TO check response of particular id should be diff through jmeter

MY response for api is:-
"data":{"shortId":"lu131559"}}
Now i wants to check short id is different for every virtual user.
mns if second hit gone response data is
lu131560
So i want to validate that after 1000 request from virtual user every time i am getting diff id.
If you know the "current" value of the shortId and expect it to be incremented by 1 each time you call your API you can go for Response Assertion and use __intSum() and __counter() functions combination in the pattern like:
lu${__intSum(131559,${__counter(,)},)}
Each time the Assertion will be called it will expect the value to be incremented by one, i.e.
lu131560 - for 1st user or iteration
lu131561 - for 2nd user or iteration
lu131562 - for 3rd user or iteration
etc.
More information: Apache JMeter Functions - An Introduction

How to pass response body values from one thread to different threads by incrementing the values in the response body in JMETER

I just wanted to extract value from the response body of thread1(1st thread am running once by passing number of threads and loop count 1 each) and need to pass same for the 2nd thread(2nd thread am running multiple times by passing number of threads 10).
This is my response body from Thread1.
{"availablePhoneNumbers":["3052191421","3052192726","3052192566","3052195123","3052194493","3052199654","3052194684","3052199164","3052190020","3052190352"]}
i just wanted to pick the first data 3052191421 and wanted to run in thread2 for all the HTTP requests.
then 2nd data 3052192726
then 3rd data and so on.
Could you please get the solution for this?
Thanks in advance..
Extract first number from the response. This can be done using JSON Extractor configured like:
Names of created variables: number
JSON Path Expressions: $.availablePhoneNumbers[0]
Later on you will be able to use __longSum() function in order to:
add 1 to ${number} variable
return the value
save the result back into the ${number} variable
Demo:

How to skip remaining transactions and go to next iteration based on the value captured

in jmeter script, is it possible to skip the remaining transactions and go to next iteration based on a captured value?
eg:
Thread Group1:
Sampler 1
Sampler 2
Sampler 3
whenever the value captured in Transaction 2 is 0, it should skip Transaction 3 and go to next iteration.
Right click Transaction 3 choose Insert Parent and add If Controller with condition checking that value isn't 0:
${jexl3("${value}" != "0")}
If you have saved value from transaction 2, just add Post Processor og Regular expression or JSON extractor depending on your response.
You can do it using the following function. I have also provided the link to the previous answer from VINS.
ctx.setRestartNextLoop(true);
jmeter stop current iteration

JMeter and random variable along with if controller

i want to control my sampler execution by using a random variable . I have a sequence of hits login,welcome,Bla,log out . i want the log out to be performed for 6/10 requests and let others do not login(so to speak 6 requests will perform the whole sequence including log out, 4 of them will perform will not perform log out ).How to achieve the same in JMETER
I have added a random variable rand and set it between 1-10 at the beginning of the thread group .Then just above Logout sampler i placed an IF controller were i check ${rand}>4 . How ever i always get all sequence executed . Please suggest what am i doing wrong
Your approach is a little bit weird, my expectation is that the problem is in the following areas:
Your IF Controller condition is wrong (check jmeter.log file for any suspicious entries)
Your random variable setting is wrong, i.e. it has the same value for all virtual users (threads) so they will either be executed all or none
So I would recommend using Throughput Controller or Switch Controller in order to set up this 60/40 distribution.
See Running JMeter Samplers with Defined Percentage Probability article for more details.
Random Variable in Jmeter is saved in long format be default so
${rand} > 4 won't work. You need to change
Condition to ${rand} > 4.0
or change Random Variable Output format to 00 (2 digits)
see Manual
This was accomplished by creating a combination of config element- random variable and an IF controller
1) a random variable was created with Minim and maxim value to meet above condition
2) and IF controller was able to check ${myrand}>4;
This had derived the desired result - thank you all

Resources