 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 verify JSON response headers in Rest Assured?
We can verify JSON response headers in Rest Assured. This is achieved with the help of the header method. We shall send a GET request via Postman on a mock API, observe the Response Headers.
Headers −

Example
Using Rest Assured, we shall verify the value of the Content-Length in the Headers.
Code Implementation
import org.hamcrest.Matchers; import org.testng.annotations.Test; import static io.restassured.RestAssured.given; import io.restassured.RestAssured; public class NewTest {    @Test    public void ressponseAssertion() {       //base URL       RestAssured.baseURI = "https://run.mocky.io";       //GET operation       given() .when().get("/v3/6c6ed634-5e78-4b80-94c7-cf17c04c7055").       then().log().all()       //verify status code as 200       .assertThat().statusCode(200)       //verify body       .body("Location", Matchers.equalTo("Makinac Island"))       //verify header       .header("Content-Length" , "57");    } }  Output

Advertisements
 