responserest-assuredtime-wait

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


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


Solution

  • 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();
    }