Why does HTTP request doesn't execute after IF Controller - jmeter

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.

Related

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 - Re-use response data in follow-up requests

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

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

Save Responses to a file Listerner - Setting file name

I've a JMeter test plan with a number of HTTPRequests. For each HTTPRequest I have added a "Save Responses to a file" Listener when a failure occurs. Ideally I would like the file name to be the same as the label of the Request it is logging it for with a suffix "_FAILURE" added.
Is there any way of using a single "Save Responses to a file" Listener at the top level of my plan and having this be generated automatically rather than having to set manually myself for each?
Any listener has access to SampleResult of sampler that was run last. You can get it using __Beanshell function. SampleResult has method for getting sampler label. So filename prefix of Save Responses to File listener will be:
${__BeanShell(SampleResult.getSampleLabel())}_FAILURE

Resources