Skip to content

Commit 912727d

Browse files
Postman API Testing Masterclass code added
1 parent ebe7ce4 commit 912727d

File tree

8 files changed

+242
-0
lines changed

8 files changed

+242
-0
lines changed
95.3 KB
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
json-server
2+
3+
1. Open Terminal
4+
2. Run command
5+
6+
```bash
7+
json-server file_name
8+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"students": [
3+
{
4+
"id": "1",
5+
"name": "John",
6+
"location": "India",
7+
"phone": "1234567890",
8+
"courses": [
9+
"Java",
10+
"Selenium"
11+
]
12+
},
13+
{
14+
"id": "2",
15+
"name": "Kim",
16+
"location": "US",
17+
"phone": "987654321",
18+
"courses": [
19+
"Python",
20+
"C"
21+
]
22+
},
23+
{
24+
"name": "Smith S.",
25+
"location": "France",
26+
"phone": "1345678789",
27+
"courses": [
28+
"JavaScript",
29+
"Java"
30+
],
31+
"id": "3"
32+
}
33+
]
34+
}
Binary file not shown.
47.1 KB
Binary file not shown.
67.3 KB
Loading
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# Postman API Testing Master Class 🔥🚀
2+
3+
## 01. Introduction ✅
4+
5+
### Types of API
6+
7+
**There are two types of API's,**
8+
9+
1. Simple Object Access Protocol (SOAP)
10+
2. Representational State Transfer (REST)
11+
12+
Both are the web services.
13+
14+
### API vs WebServices
15+
16+
- Web Service is an API wrapped in HTTP.
17+
- All Web Services are API but APIs are not Web Services.
18+
- A Web Service needs a network while an API doesn't need a network for its operation.
19+
20+
## 02. Environment Setup ✅
21+
22+
_Postman - API testing tool_
23+
24+
- We can do manual testing of API's using postman.
25+
- Web / Desktop testing.
26+
- Workspace: Area where we maintain files and saved.
27+
- Create workspace, rename and delete.
28+
- Creating Collection - contains number of folders and http requests.
29+
(Create, Rename, Delete and Run the collection)
30+
- We can create any number of collections under workspace.
31+
32+
### HTTP Request
33+
34+
**REQUEST ➡️ APIs ➡️ RESPONSE**
35+
36+
**_GET_** ➡️ Retrieve the resource from database
37+
**_POST_** ➡️ Create resource on database
38+
**_PUT_** ➡️ Update existing resource on database
39+
**_DELETE_** ➡️ Delete existing resource from database
40+
**_PATCH_** ➡️ Update partial details of resource
41+
42+
![APIs Requests](API%20Requests.jpg)
43+
44+
### Validations
45+
46+
**status code**
47+
**time**
48+
**size data**
49+
**response body(json/xml)**
50+
**cookies**
51+
**headers**
52+
53+
### HTTP Status Code
54+
55+
![Status Codes](Status%20Codes.jpg)
56+
57+
## 03. Creating Our Own APIs ✅
58+
59+
### Creating our own APIs
60+
61+
**Step1 - Install NodeJS**
62+
63+
**Step2 - Check Node and npm package manager version**
64+
65+
```bash
66+
node -v
67+
npm -v
68+
```
69+
70+
**Step3 - Install json-server**
71+
72+
```bash
73+
npm install -g json-server
74+
```
75+
76+
### Test / Validations
77+
78+
**JSON - JavaScript Object Notation**
79+
80+
**Key Value Pairs => key:value**
81+
82+
**_key is always included in "" quotation_**
83+
84+
### json-server
85+
86+
1. Open Terminal
87+
2. Run the following command to run API testing
88+
89+
```bash
90+
json-server file_name
91+
```
92+
93+
```json
94+
{
95+
"firstname": "John",
96+
"secondname": null,
97+
"age": 30,
98+
"phone": 1234567890,
99+
"status": true
100+
}
101+
```
102+
103+
**Student Data**
104+
105+
```json
106+
{
107+
"students": [
108+
{
109+
"sid": 101,
110+
"sname": "John",
111+
"grad": "A"
112+
},
113+
{
114+
"sid": 102,
115+
"sname": "Kim",
116+
"grad": "B"
117+
},
118+
{
119+
"sid": 103,
120+
"sname": "Scott",
121+
"grad": "C"
122+
}
123+
]
124+
}
125+
```
126+
127+
### JSON vs XML
128+
129+
![JSON and XML](JSON%20and%20XML.jpg)
130+
131+
## 04. API Response Validations ✅
132+
133+
### Response Validations
134+
135+
**Status Code**
136+
**Headers**
137+
**Cookies**
138+
**Response time**
139+
**Response body**
140+
141+
### Assertion Validation
142+
143+
**pm - is a Library**
144+
**_Functions/ Assertions are available for assertion validations._**
145+
**_These Functions are written in JavaScript. Postman built-in uses JavaScript._**
146+
147+
`pm.function inside JavaScript Function`
148+
149+
**_We need to write our own JavaScript function and inside that we have to use `pm.function` for assertion validations._**
150+
151+
**Normal Function**
152+
153+
```javascript
154+
pm.test (“Test Name”, function ()
155+
{
156+
// assertion;
157+
}
158+
);
159+
```
160+
161+
**Arrow Function**
162+
163+
```javascript
164+
pm.test (“Test Name”, () =>
165+
{
166+
// assertion;
167+
}
168+
);
169+
```
170+
171+
### Testing Status Codes
172+
173+
1. Go to Postman
174+
2. Create or Add a Request
175+
3. In Request, go to `Tests` tab
176+
4. Inside Test tab we have to write validation functions
177+
178+
**Test for the response status code:**
179+
180+
```javascript
181+
pm.test (“Status code is 200”, () => {
182+
pm.response.to.have.status(200);
183+
});
184+
```
185+
186+
**If you want to test for the status code being one of a set, include them all in an array and use one of:**
187+
188+
```javascript
189+
pm.test (“Successful POST request”, () => {
190+
pm.expect(pm.response.code).to.be.oneOf([201, 202]);
191+
});
192+
```
193+
194+
**Check the status code text:**
195+
196+
```javascript
197+
pm.test (“Status code name has string”, () => {
198+
pm.response.to.have.status(“Created”);
199+
});
200+
```
104 KB
Loading

0 commit comments

Comments
 (0)