Skip to main content

REST Assured Log if validation fails

Since REST Assured 2.3.1 you can log the request or response only if the validation fails.

Log Request

// To log all Request information

// To log specific request information, like in below to log Request Method

Log Response

// Log all the response information

// Log specific response information, like body in below example

// Log specific response information, like body in below example
// Set true to pretty-print 
.log().ifValidationFails(LogDetail.BODY, true)

Log Request and Response Together

// Log all detail

// Log only header or other specific detail

Log Request and Response Together - Shortcut

Use it outside given()

// To log everything

// To log request and response header

Submitted by tgoswami on September 2, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.