[Bài 10] Một số techniques liên quan đến log trong Rest-assured

I. Log request

given().log().all(). .. // Log all 
given().log().params(). .. // Log only the parameters of the request
given().log().body(). .. // Log only the request body
given().log().headers(). .. // Log only the request headers
given().log().cookies(). .. // Log only the request cookies
given().log().method(). .. // Log only the request method
given().log().path(). .. // Log only the request path

// Log if test fail
given().log().ifValidationFails(). .. 

II. Log response

get("/x").then().log().all(). .. // Log all
get("/x").then().log().body(). .. // Log body
get("/x").then().log().ifError(). .. // Log body if error
get("/x").then().log().statusLine(). .. // Only log the status line
get("/x").then().log().headers(). .. // Only log the response headers
get("/x").then().log().cookies(). .. // Only log the response cookies

// Only log if the status code is equal to 302
get("/x").then().log().ifStatusCodeIsEqualTo(302). .. 

// Only log if the status code matches the supplied Hamcrest matcher
get("/x").then().log().ifStatusCodeMatches(matcher). .. 

// Log if test fail
.then().log().ifValidationFails(). .. 

III. Config log

// Log both request and response when test fail
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); 

// Log both request and response.
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());

// Log when using allure-report
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 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments