我想使用testNG的Reporter.log()方法(它需要字符串輸入)將要打印到控制檯中的請求數據記錄到testNG報告文件。下面是我的要求規格:如何將重新審覈的請求數據記錄到testNG報告文件
private RequestSpecification getRequestSpec(ContentType requestbodytype, ContentType responsetype) {
return RestAssured.given().log().everything().contentType(requestbodytype).accept(responsetype);
}
protected Response get(String resourceURI, ContentType requestbodytype, ContentType responsetype, boolean enableUrlEncoding) {
Response rs = null;
rs = getRequestSpec(requestbodytype, responsetype).when().get(resourceURI);
Reporter.log(rs.print());
return rs;
}
我要登錄下面的內容,以測試日誌文件與響應一起,我會收到在此調用exection
Request method: GET
Request URI: http://localhost:port/url
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=application/json, application/javascript, text/javascript
Content-Type=application/json; charset=UTF-8
Cookies: <none>
Multiparts: <none>
Body: <none>
誰能幫我解決這個。
感謝
我很抱歉,這些lambda表達式在您的答案?我只能使用Java 1.7.0_45。 – user1634358