Nội dung bài viết
I. Log request
x
10
10
1
given().log().all(). .. // Log all
2
given().log().params(). .. // Log only the parameters of the request
3
given().log().body(). .. // Log only the request body
4
given().log().headers(). .. // Log only the request headers
5
given().log().cookies(). .. // Log only the request cookies
6
given().log().method(). .. // Log only the request method
7
given().log().path(). .. // Log only the request path
8
9
// Log if test fail
10
given().log().ifValidationFails(). ..
II. Log response
1
15
15
1
get("/x").then().log().all(). .. // Log all
2
get("/x").then().log().body(). .. // Log body
3
get("/x").then().log().ifError(). .. // Log body if error
4
get("/x").then().log().statusLine(). .. // Only log the status line
5
get("/x").then().log().headers(). .. // Only log the response headers
6
get("/x").then().log().cookies(). .. // Only log the response cookies
7
8
// Only log if the status code is equal to 302
9
get("/x").then().log().ifStatusCodeIsEqualTo(302). ..
10
11
// Only log if the status code matches the supplied Hamcrest matcher
12
get("/x").then().log().ifStatusCodeMatches(matcher). ..
13
14
// Log if test fail
15
.then().log().ifValidationFails(). ..
III. Config log
1
8
1
// Log both request and response when test fail
2
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
3
4
// Log both request and response.
5
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
6
7
// Log when using allure-report
8
given().filter(new AllureRestAssured()). ..
Khi đã dùng config log thì bạn không cần phải viết mục I và mục II, vì config đã được apply cho tất cả các request và response.
0