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
Related
I'm kind of new with JMeter and I have the following problem.
When If controller executes, the next block after it doesn't being executed in my example it is Send Document.
My task is to read the CSV file, check if the previous value equals to current value from the CSV file, in case if they are not equal I need to make a request to get a token, and Send Document block must execute no matter if IF Controller is true or false
How can i achieve this?
I can think of 2 options:
The request under the If Controller fails somehow and you have Stop Test as the action to be taken after a Sampler error in Thread Group
if this is the case and you want to run the 2nd request in any case - set it to Continue
You have Stop thread on EOF set to true in the CSV Data Set Config
if this is the case the test will be stopped when the CSV file runs out of values. If this is the case - set it to false as well as Recycle on EOF and put the whole block under the While Controller and use something like ${__javaScript("${your_variable_from_csv}" != "<EOF>",)} as the condition
If I'm not telepathic enough and the reason is not in 2 listed above - take a look at jmeter.log file, it normally contains sufficient information to get to the bottom of the issue.
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.
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
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
We have a service that works the following way:
First, a request with search parameters is sent, for which we get back a searchId. This searchId is then used to continue fetching information until service response it has no more data left (hasMore parameter becomes "false").
The question is this - I have set up jMeter to send first requests, but not certain how then to keep sending requests in parallel for each response in the Thread Group, and need your advice on it. My thought was to set up another Thread Group since I cannot set it inside the first one, but then how do I get access to responses and process them in parallel?
EDITED:
This is what I ended up with. First Beanshell Sampler extracts searchId and hasMore and puts it into vars. Second Sampler extracts hasMore and again puts it into vars, overwriting the first. At the end, the While loop worked as intended, using ${__javaScript("${hasMore}" == "1",)}.
I would recommend designing your test as follows:
Request to get searchId
While Controller with condition like ${__javaScript("${hasMore}" != "false",)}
Request to continue to fetch information
PostProcessor to extract hasMore parameter and store it into the relevant JMeter Variable
This way "fetch information" requests will be executing until hasMore parameter becomes false. See Using the While Controller in JMeter article for more details.
I suggest 2 Thread group
First Thread group:
Save searchIds in file (JSR223 Sampler) or database (JDBC Sampler) with key as counter (1,2,...) and value as the searchId value
Save a number of IDs in property ${__setProperty(threadCount,${counter})}.
Second Thread group:
In definition - Number of thread use ${__P(threadCount)}
Read from file (JSR223 Sampler) or database (JDBC Sampler)
using ${__threadNum} as key get the relevant searchId you need