Skip to content

Commit 1c514cd

Browse files
committed
added logger in restful booker end to end tests
1 parent 6dec6de commit 1c514cd

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/BaseTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6+
import com.microsoft.playwright.APIResponse;
67
import io.github.mfaisalkhatri.api.manager.RequestManager;
8+
import io.github.mfaisalkhatri.api.restfulecommerce.Logger;
79
import org.testng.annotations.AfterTest;
810
import org.testng.annotations.BeforeTest;
911

@@ -31,4 +33,9 @@ public void tearDown() {
3133
this.manager.disposeAPIRequestContext();
3234
this.manager.closePlaywright();
3335
}
36+
37+
protected void logResponse (final APIResponse response) {
38+
final Logger logger = new Logger (response);
39+
logger.logResponseDetails ();
40+
}
3441
}

src/test/java/io/github/mfaisalkhatri/api/restfulbooker/tests/RestfulBookerEndToEndTests.java

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void createBookingTest() {
3535
final APIResponse response = this.manager.postRequest("/booking", RequestOptions.create()
3636
.setData(this.bookingData));
3737

38+
logResponse (response);
3839
assertEquals(response.status(), 200);
3940

4041
final JSONObject responseObject = new JSONObject(response.text());
@@ -51,6 +52,7 @@ public void createBookingTest() {
5152
@Test
5253
public void getBookingTest() {
5354
final APIResponse response = this.manager.getRequest("/booking/" + this.bookingId);
55+
logResponse (response);
5456
assertEquals(response.status(), 200);
5557

5658
final JSONObject responseObject = new JSONObject(response.text());
@@ -67,6 +69,7 @@ public void updateBookingTest() {
6769
final APIResponse response = this.manager.putRequest("/booking/" + this.bookingId, RequestOptions.create()
6870
.setData(updateBookingData)
6971
.setHeader("Cookie", "token=" + this.token));
72+
logResponse (response);
7073
assertEquals(response.status(), 200);
7174

7275
final JSONObject responseObject = new JSONObject(response.text());
@@ -82,6 +85,7 @@ public void generateTokenTest() {
8285
final Tokencreds tokenData = getToken();
8386
final APIResponse response = this.manager.postRequest("/auth", RequestOptions.create()
8487
.setData(tokenData));
88+
logResponse (response);
8589
assertEquals(response.status(), 200);
8690

8791
final JSONObject responseObject = new JSONObject(response.text());
@@ -99,6 +103,7 @@ public void updatePartialBookingTest() {
99103
.setData(partialBookingData)
100104
.setHeader("Cookie", "token=" + this.token));
101105

106+
logResponse (response);
102107
assertEquals(response.status(), 200);
103108
final JSONObject responseObject = new JSONObject(response.text());
104109

@@ -111,12 +116,14 @@ public void deleteBookingTest() {
111116
final APIResponse response = this.manager.deleteRequest("/booking/" + this.bookingId, RequestOptions.create()
112117
.setHeader("Cookie", "token=" + this.token));
113118

119+
logResponse (response);
114120
assertEquals(response.status(), 201);
115121
}
116122

117123
@Test
118124
public void testBookingDeleted() {
119125
final APIResponse response = this.manager.getRequest("/booking/" + this.bookingId);
126+
logResponse (response);
120127
assertEquals(response.status(), 404);
121128
}
122129
}

test-suite/testng.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
3-
<suite name="APi Test Automation with Playwright">
3+
<suite name="API Test Automation with Playwright">
44
<suite-files>
55
<suite-file path="testng-reqres.xml"/>
66
<suite-file path="testng-restfulbooker.xml"/>

0 commit comments

Comments
 (0)