@@ -48,56 +48,7 @@ Each scenario validates real user interactions, UI consistency, business logic,
4848
4949---
5050
51- ## 🔗 API Testing
52-
53- The framework supports API testing using Playwright's built-in APIRequestContext. You can:
54- - Validate REST endpoints (GET, POST, PUT, DELETE, etc.)
55- - Chain API and UI flows
56- - Save API responses as JSON artifacts for traceability
57-
58- ** API test files are located in:**
59- ```
60- tests/api/
61- ```
62- ** API response artifacts are saved in:**
63- ```
64- apiresponse/
65- ```
66-
67- ### Example: JSONPlaceholder API Test
68- ``` js
69- const { test , expect } = require (' @playwright/test' );
70- const { saveApiResponse } = require (' ../../utils/saveApiResponse' );
71-
72- const API_URL = ' https://jsonplaceholder.typicode.com' ;
73-
74- test (' should GET a post' , async ({ request }) => {
75- const response = await request .get (` ${ API_URL } /posts/1` );
76- expect (response .status ()).toBe (200 );
77- const body = await response .json ();
78- saveApiResponse (' jsonplaceholder_get_post' , body);
79- expect (body).toHaveProperty (' id' , 1 );
80- });
8151
82- test (' should POST a new post' , async ({ request }) => {
83- const payload = { title: ' foo' , body: ' bar' , userId: 1 };
84- const response = await request .post (` ${ API_URL } /posts` , {
85- data: payload,
86- headers: { ' Accept' : ' application/json' }
87- });
88- expect (response .status ()).toBe (201 );
89- const body = await response .json ();
90- saveApiResponse (' jsonplaceholder_post_post' , body);
91- expect (body).toHaveProperty (' id' );
92- });
93- ```
94-
95- API tests can be run with:
96- ``` bash
97- npx playwright test tests/api/JSONPlaceholderAPITests.spec.js
98- ```
99-
100- ---
10152## 🧪 Automated Test Scenarios
10253
10354
@@ -175,6 +126,56 @@ Tests are business-readable, with implementation details handled in page objects
175126
176127---
177128
129+ ## 🔗 API Testing
130+
131+ The framework supports API testing using Playwright's built-in APIRequestContext. You can:
132+ - Validate REST endpoints (GET, POST, PUT, DELETE, etc.)
133+ - Chain API and UI flows
134+ - Save API responses as JSON artifacts for traceability
135+
136+ ** API test files are located in:**
137+ ```
138+ tests/api/
139+ ```
140+ ** API response artifacts are saved in:**
141+ ```
142+ apiresponse/
143+ ```
144+
145+ ### Example: JSONPlaceholder API Test
146+ ``` js
147+ const { test , expect } = require (' @playwright/test' );
148+ const { saveApiResponse } = require (' ../../utils/saveApiResponse' );
149+
150+ const API_URL = ' https://jsonplaceholder.typicode.com' ;
151+
152+ test (' should GET a post' , async ({ request }) => {
153+ const response = await request .get (` ${ API_URL } /posts/1` );
154+ expect (response .status ()).toBe (200 );
155+ const body = await response .json ();
156+ saveApiResponse (' jsonplaceholder_get_post' , body);
157+ expect (body).toHaveProperty (' id' , 1 );
158+ });
159+
160+ test (' should POST a new post' , async ({ request }) => {
161+ const payload = { title: ' foo' , body: ' bar' , userId: 1 };
162+ const response = await request .post (` ${ API_URL } /posts` , {
163+ data: payload,
164+ headers: { ' Accept' : ' application/json' }
165+ });
166+ expect (response .status ()).toBe (201 );
167+ const body = await response .json ();
168+ saveApiResponse (' jsonplaceholder_post_post' , body);
169+ expect (body).toHaveProperty (' id' );
170+ });
171+ ```
172+
173+ API tests can be run with:
174+ ``` bash
175+ npx playwright test tests/api/JSONPlaceholderAPITests.spec.js
176+ ```
177+
178+ ---
178179
179180
180181## ▶️ How to Run the Tests
0 commit comments