Ruwan Kayaal Ruwan Kayaal - 2 months ago 11
reST (reStructuredText) Question

jMeter send http request by condition

I have a jMeter Test Plan with 2 http requests: submit and retrieve.
First one submits some data to server. That's ok.

Then, with the second task I have to retrieve information from server. Response is json, containing taskStatus, which can be "pending" or "done". Logic is as follows:
if taskStatus is "pending" I have to repeat this http request with some delay (for example, 3 seconds) automatically.
However, I found no way of doing this with Http Request Sampler. Hope someone can help me. (Using Http Request Sampler is not a must)

Answer

It cannot be done with Http Request Sampler alone, but While Controller is to the rescue.

Structure your test like this:

enter image description here

Where:

  • Reset status (ShellBean Sampler, or any other programmable sampler) is the first item that runs that test starts. It will reset the state of test, so that it won't be confused by previous iteration. All it does is:

    enter image description here

  • Submit stays as is, but Retrieve moves under a While Controller and has a post-processor attached to it now. Those 2 elements together (While controller and post-processor, make sure that Retrieve runs in loop, and that loop exists as soon as status becomes 'done'. So

  • While Controller looks like this:

    enter image description here

    i.e. it checks the value of the variable "Status" and only enters the loop if status is not 'done' (${__javaScript("${Status}"!="done")})

  • Finally someone needs to update ${Status} variable after each execution of Retrieve. That is done by Extract status from response. For post-processor I cannot be more specific, since you didn't say how your result looks, but you basically need to configure it to extract status (either 'pending' or 'done' and save it in the variable ${Status}. It may look like this (just an example, your syntax, or even type of post-processor may be different, depending on type of the response):

    enter image description here

So here's an example of how this test would run, if it was receiving 'done' only after several iterations:

enter image description here