Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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

Advertisements