Category:
Rest Assured
This ValidatableResponseOptions interface has overloaded time() methods which accepts Matcher.
- time(Matcher matcher) – Validate that the response time (in milliseconds) matches the supplied matcher.
- time(Matcher macther, TimeUnit timeunit) – Validate that the response time matches the supplied matcher and time unit.
// Calling POST method on URI. After hitting we get Response
Response response = request.post();
// Getting ValidatableResponse type
ValidatableResponse valRes = response.then();
// Asserting response time is less than 2000 milliseconds
// L just represent long. It is in millisecond by default.
valRes.time(Matchers.lessThan(2000L));
// Asserting response time is greater than 2000 milliseconds
valRes.time(Matchers.greaterThan(2000L));
// Asserting response time in between some values
valRes.time(Matchers.both(Matchers.greaterThanOrEqualTo(2000L)).and(Matchers.lessThanOrEqualTo(1000L)));
// If we want to assert in different time units
valRes.time(Matchers.lessThan(2L), TimeUnit.SECONDS);