简体   繁体   中英

How to log RestAssured Request and Response information log in ExtentReports logs

I am using rest-assured lib and extent report for reporting,

ValidatableResponse reponseManualLead = given().header("Accept", "application/json")
                .contentType("application/json").header("Authorization", access_token)
                .body(requestBody).log().body().when()
                .put(losdevUrl + "/endUrl").then().log().all();

log().all() : Pritn log of request/reponse in console log , I need that to be log in extentreport , can we do that.

ExtentTestManager.getTest().log(LogStatus.INFO, "Response is:<br>" + "here");

The recommended usage to include JSON request/response is via MarkupHelper as in the documentation: http://extentreports.com/docs/versions/4/java/#markup-helpers-codeblock

Markup m = MarkupHelper.createCodeBlock(json, CodeLanguage.JSON);
test.pass(m);

// shorthand
test.pass(MarkupHelper.createCodeBlock(json, CodeLanguage.JSON));

The code block will be prettified and display like so:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM