How to setup time to wait for response in Rest-Assured?

IrinaG picture IrinaG · Oct 29, 2017 · Viewed 10.5k times · Source

Response takes a long time to come. How it is possible to wait for response time in rest-assured ?

Answer

Ciaran George picture Ciaran George · Nov 7, 2017

In the past I've used awaitility, it allows you to wait for a response from the service before kicking off another call.

https://github.com/awaitility/awaitility.

You can return an extracted response and wait for the status code/body to return a value.

@Test
public void waitTest() throws Exception {
    Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> this.getStatus() == 200)
}

public int getStatus() {
    return given()
        .accept(ContentType.JSON)
        .get(url)
        .then()
        .extract()
        .statusCode();
}