0

Once I send GET request , I am able to get 200 OK. In response body, there is a key, consider that is "field_name". Currently "field_name" value is "start".After some time, value is changes to stop.

Expected O/P : want to run it till i do not get the "field_name":"stop" in response body.

Parth Makwana
  • 51
  • 1
  • 9
  • So, you want to perform GET requests in a loop until value changes to `stop`? – Fenio Aug 01 '19 at 05:20
  • @Fenio yes! on a start basis it's value is start and after some time it changes to stop. So want to perform it till i do not get stop as a value of field_name – Parth Makwana Aug 02 '19 at 05:03
  • Check my answer – Fenio Aug 02 '19 at 05:16
  • Can your application make use of async behavior? If yes then take a look at AsyncHttpClients. AsyncHttpClients can wait for the result from the server and in your scenario can continue processing until the server does not return a "stop". – Lalit Mehra Aug 02 '19 at 05:24

1 Answers1

0

How about using while loop, perform GET request inside, get the status and put the Thread to sleep?

String field_name = "start";
while (field_name.equals("start")) {
    try {
        Thread.sleep(500);
    } catch (InterruptedException ignore) {
    }
    Response response = when().get("my url").then().extract().response();
    field_name = response.jsonPath().getString("path.to.field_name");
}

In the above code, I assumed that field_name is start. The loop begins, we wait for 500 milliseconds and after that time, we perform GET request, extract its response and get the field_name value.

If the field_name value equals stop then the loop will no longer be executed. If the loop equals start then we wait for another 500 milliseconds, perform GET, get the status etc...

Hope it helps!

Fenio
  • 3,528
  • 1
  • 13
  • 27