Skip to main content

REST Assured Log Response if Error or Status Code Matches Some Value

If you're only interested in printing the response body if an error occur then you can use:

.log().ifError()

make sure you are using .log().ifError() just after than otherwise logs will not show. It logs everything only if an error occurs (status code >= 400).

REST Assured Log only the status

.log().status();		

REST Assured Log if status code is equal to

.log().ifStatusCodeIsEqualTo(202)

log if the status code matches the supplied Hamcrest matcher

.log().ifStatusCodeMatches(equalTo(200));	

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.

About

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.