Response takes a long time to come. How it is possible to wait for response time in rest-assured ?
How to setup time to wait for response in Rest-Assured?
21k Views Asked by IrinaG At
2
There are 2 best solutions below
0
On
On this class you declared the max time
public interface Constants {
Long MAX_TIMEOUT = 3000l;
}
Here on this class you implement the interface
public class BaseTest implements Constants {
@BeforeClass
public static void setup() {
ResponseSpecBuilder resBuilder = new ResponseSpecBuilder();
resBuilder.expectResponseTime(Matchers.lessThan(MAX_TIMEOUT));
RestAssured.responseSpecification = resBuilder.build();
}
Finally you can use the waiter strategy
public class SimulationTest extends BaseTest {
@Test
public void checkStatus200() {
given()
.when()
.get()
.then()
.statusCode(200)
;
}
}
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.