

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the response time of a request in Rest Assured?
We can get the response time of a request in Rest Assured. The time elapsed after a request is sent to the server and then receiving the response is known as the response time.
The response time is obtained in milliseconds by default. However, we can also obtain in other time units. The below methods of the ResponseOptions interface can be used to get the response time −
- getTime - it gets the response time in milliseconds.
- getTimeIn(time unit) - it gets the response time in the time unit passed as a parameter to this method.
- time() - it gets the response time in milliseconds.
- timeIn(time unit) - it gets the response time in the time unit passed as a parameter to this method.
Example
Code Implementation
import org.testng.annotations.Test; import io.restassured.RestAssured; import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; public class NewTest { @Test public void responsetime() { //base URI with Rest Assured class RestAssured.baseURI ="https://www.tutorialspoint.com/index.htm"; //input details RequestSpecification r = RestAssured.given(); // GET request Response res = r.get(); //obtain Response as string String j = res.asString(); //get response time long c = res.getTime(); System.out.println("Response time in milliseconds: " + c); } }
Output
- Related Questions & Answers
- How to validate the response time of a request in Rest Assured?
- Explain how to get the size of a JSON array response in Rest Assured.
- How to parse a JSON response and get a particular field from the response in Rest Assured?
- How to validate XML response in Rest Assured?
- Explain DELETE request in Rest Assured.
- Explain PUT request in Rest Assured.
- How to use Assertion in response in Rest Assured?
- How to verify JSON response headers in Rest Assured?
- How to update the value of a field in a request using Rest Assured?
- How to transform the response to the Java list in Rest Assured?
- How to extract the whole JSON response as a string in Rest Assured?
- How to verify a JSON response body using Assertions in Rest Assured?
- How to incorporate TestNG assertions in validating Response in Rest Assured?
- How to pass more than one header in a request in Rest Assured?
- How to pass the request body from an external file in a separate package in Rest Assured?
Advertisements