Response Logging in REST Assured

Profile picture for user devraj

In this one we are going to log the response. For request we log after given() for response we log after then(). You can log cookies, status, headers, body and all components at once. Check below example:

public class DummyRestAPIExample 
{
	@BeforeClass
	public void setup()
	{
		RestAssured.baseURI = "https://reqres.in";
		RestAssured.basePath = "/api";
	}
	
	@Test
	public void postMethodExample()
	{
		given()
			.body("{" + 
					"\"name\":\"Tarun Goswami\",\n" + 
					"\"job\":\"QA\",\n" + 
					"}")
		.when()
			.post("/users")
		.then()
			.log()
//			.cookies()
			.status()
//			.headers()
//			.body()
//			.all()
			.statusCode(201);			
	}
}

Uncomment the component in above example which you want to log.