Skip to content
CodeKruPro

Log requests and responses only on failure

Automation taskMediumJava only

"A test failed in CI. How do you see what was sent and received?" The answer is log().ifValidationFails(), which keeps logs short until something breaks. You practise it in this lesson.

Response Logging on Failure

Response Logging on Failure

You can also log the response on validation failure:

.then()
    .log().ifValidationFails()  // logs response if assertions below fail
    .statusCode(200);

Combine request and response logging for full debugging:

given().log().ifValidationFails()  // request
.when().get(path)
.then().log().ifValidationFails()  // response
.statusCode(200);

Task: Validate two endpoints with response-level conditional logging.

Expected output:

Response validation passed
Product validation passed