Jmeter- how to break while controller after getting successful repsonse - jmeter

I am seeking help on how to break while controller loop when I got successful response.
Steps:-
1. I have a while controller where I kept below logic
${__javaScript((${controller} < 5),)}
2. And inside while controller I have created http request which return response.
This request takes some time to give result.if this request is still
running it will return status code 202.. and if this request is completed it will give 200.(I have another API to check this)
So here I dont know when it will get success.
for that after each request I have kept waiting time.
So when I call first time after while loop.. its giving 202(because its still running)
and I will continue this process till 5 times..
So here there is chance I can get 200 success code at 3rd request.
So what I want here is I would like to break the loop after that..I dont want to run till 5 times.
I am using below code to read the response.
if (status_code == "200"){
AssertionResult.setFailure(false);
}
So when I get the 200 from response it should stop and get success
and if I dont get 200 from response in all 5 attempts, it should get failed.

Add Regular Expression Extractor as a child of the API request and configure it as follows:
this will extract the API HTTP Status code and store it into ${responseCode} variable
Amend your While Controller's Condition to use the following __jexl3() function
${__jexl3(${__jm__While Controller__idx} < 5 && "${responseCode}" != "200",)}
That's it, assuming above setup your While Controller will break in 2 cases:
Response code is 200
API request is executed 5 times
More information: Using the While Controller in JMeter

Related

Extracting response and using While Controller to wait for response in Jmeter

All, I need additional assistance. I have tried researching and was using this following resource guide. https://www.blazemeter.com/blog/using-while-controller-jmeter
Problem
I need to Implement a way to wait for a specific Response from the server and record the time it takes from the start of the request to the end where I get a response of Complete in Jmeter. I have been looking at while controller and researching it.
Problem#1
If I add a while controller, my request failed because its adding multiple token. If I leave it without the while controller then it only gets 1 bearer token and it is able to submit a get request and get the response appropriately. I am suspecting there is a pre-procession somewhere else in my script that doing this...
Uses beanshell preprocesser to grab the token
sampler.getHeaderManager().add(new Header("Authorization","Bearer " + vars.get("BEARER")));
Problem #2
I have a GET Request to check the status of the request. Response in the BODY comes back as this json
"{"Status": "RECEIVED", "DllUrl": "", "Message": " "}"
I need it to continue checking for the status of COMPLETE……..also may need to check for failed as well
Was looking at regular Expression extractor to get the status and only stop until it finds COMPLETE status. That way I can measure time start and end time for completion. Any help and guidance will be helpful.
You're adding a header and not removing the previous one therefore it adds another header on each iteration.
In fact you don't need to do any scripting for this, you can just define the header in the HTTP Header Manager:
With regards to extracting this Status value, it's better to do it using JSON Extractor configured like:
Once done you can use the following __jexl3() function to "wait" till the operation finishes:
${__jexl3("${status}" != "COMPLETE",)}

How to loop a sampler in a thread group in Jmeter until a specific response value is returned

I have to performance test an application which does a PDF to PNG image conversion. For that, I have 3 requests to be sent, ie, 1 POST and 2 GET requests. My requirement is to measure the performance of one the GET request which does the conversion part and downloads the converted PNG file. Note that this GET request that download the image is dependent on the other POST and the GET request which checks the status of the job. The full work flow in a nutshell is as follows:
Send a POST request to trigger a job to generate a unique identifier string.
Using the string value generated in step 1 above, the GET request checks the status of creation of a PDF document. Since this process has dependencies, the GET request polls until a status of 'Complete' is returned in its response. If the response status is not 'Complete', then we have to retry this GET request.
And finally, once the response from step 2 is returned as 'Complete', the GET request to convert the generated PDF to PNG image has to be triggered.
So 3 requests above are dependent to each other and has to run sequentially as the input for one is the output of the previous request. So we have to run this in the same order (1__> 2 --> 3) for the entire duration of the performance test.
I have tried using the While controller, however, the issue I am facing is, the sampler inside the While controller (ie GET request in step 2 which checks the status) is getting executed only for a limited number of times and not for the entire test duration.
The jmx file I have created is as follows:
Test Plan{
Thread Group{
POST Request sampler{ //step 1
//stores unique string response to variable
}
User Defined variable (initialize a Status variable to null string, initialize a counter variable)
While Controller(condition '${__javaScript("${Status}" == "" && (${counter} < 4),)}')
{
GET Request Sampler { //step 2
Regular expression extractor to get the status from response and store to variable
}
JSR223 Post processor { //to check if the status value = 'Complete', otherwise set status back to null string
/*
String status = vars.get("labelStatus")
if(status.equals("Complete")){
log.info("Label Status is Complete");
}
else{
vars.put("labelStatus","")
}
*/
}//end of JSR223 post processor
}//end of while loop
GET Request sampler to download the PNG image //step 3
} // end of Thread Group
}//end of Test Plan
screenshot of my Jmeter script:
Ideally for each POST request I make (step 1), there should be a corresponding GET request (step 2) which checks for a particular status in response. If the response contains the matching text, then have to exit the while loop and continue with the next sampler (ie GET request in step 3 above) in the thread group. This needs to be repeated in each iteration.
As per your While Controller condition its children will be executed while ${Status} variable is empty or 4 times, whatever comes the first.
I fail to see where do you update the value of the ${Status} variable, it might be the case you made a typo and need to change it to ${labelStatus}?
I would recommend using Debug Sampler and View Results Tree listener combination in order to check the values of ${labelStatus} and ${counter} variables for each While Controller's iteration
Also pay attention to JMeter Scoping Rules as your last JSR223 PostProcessor is being executed after every sampler in the Thread Group and this is something you might want to change.

Is there anyway to hold response until we get full response from server in Jmeter?

The services I'm trying to test, will work on long pooling method.
They won't give results in first response.
When I run my API script I am not getting full response in first time.
How can I wait in this case for the remaining portion of response to be received?
I want to use values from this response into next call..
In the above screen my response should wait when complete:True
As far as I understand your requirement you need to repeat the Gethotels request until complete attribute becomes true.
In order to accomplish this:
Add a JSON Extractor as a child of the Gethotels request and set it up as follows:
Put your Gethotels request under the While Controller and use the following __jexl3() function as the condition:
${__jexl3("${complete}" != "true",)}
That's it, While Controller loop the Gethotels request until complete becomes true

Jmeter- How to make a request wait until I get a specific response

Request is as :
request_a is sent and i get a response as "in progress"
Again, request_a is sent and i get a response as "in progress"
Again, request_a is sent and i get a response of "complete data"
What happening in my target server when its responds "in progress" is that the server is taking time to cache the data in the server. Here, the 3rd request is returned with complete data.
What I need is : all 3 requests should wait until it gets complete data. So that I can check the real load of the request_a connecting to database-fetching data and giving response
Note: I am checking by clearing the cache manually from the server.
Put your request under the While Controller. Use the following __jexl3() function as the Condition:
${__jexl3("${response}" != "complete data",)}
Use a suitable Post-Processor to extract the response into a JMeter Variable. For example the following Regular Expression Extractor setup would fit:
That's it, While Controller will loop over until ${response} variable won't become complete data

How to read JSON Extractor in JMeter using while controller?

My scenarios is: I have created an object and I have to pull the logs for that object. Log contains 10 IDs each have status like running or finished etc.
I want to check status for each ID, if it is finished then need to run next sampler; if failed then, exit the loop.
I tried while controller with condition ${__javaScript("${IDstatus}" !="FINISHED")}. Loop never exit, even status is finished.
Your JSON response contains finished string, and your are comparing it with FINISHED. Strings in JavaScript are case sensitive so x != X
So my expectation is that if you change your While Controller condition to
${__javaScript("${IDstatus}" !="finished")}
your While Controller will start working as expected.
References:
JavaScript Comparison and Logical Operators
JavaScript Variables
Using the While Controller in JMeter

Resources