├── QA.postman_environment.json ├── README.md ├── Users.postman_collection.json ├── Users.postman_test_run.json ├── newManCommands.txt ├── newman ├── Users-2022-11-15-09-29-30-344-0.html └── Users-2022-11-15-09-30-28-809-0.html └── test_data_Create_User.csv /QA.postman_environment.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "c5c74082-0432-4eed-a32d-28fd15d5a010", 3 | "name": "QA", 4 | "values": [ 5 | { 6 | "key": "base_url", 7 | "value": "https://reqres.in", 8 | "type": "default", 9 | "enabled": true 10 | }, 11 | { 12 | "key": "endpoint_get_user", 13 | "value": "/api/users", 14 | "type": "default", 15 | "enabled": false 16 | } 17 | ], 18 | "_postman_variable_scope": "environment", 19 | "_postman_exported_at": "2022-11-15T09:18:38.010Z", 20 | "_postman_exported_using": "Postman/10.2.2" 21 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PostmanAPITestingFramework 2 | ## Framework Overview 3 | 4 | This framework is designed for testing open-source APIs and automating validations for API responses. 5 | 6 | ## Technologies Used: 7 | - **JavaScript** for programming. 8 | - **NewMan** for CLI integration. 9 | - **Data-Driven Testing** when required. 10 | - Integration with different environments based on use case (currently tested with **QA environment**). 11 | 12 | ## Features: 13 | - **Pre-request Script**: Set up for one of the API requests. 14 | - **API Response Validation**: Tests are used to validate the API responses received. 15 | - **Query Parameters**: Set in variables for easy customization and testing. 16 | - **Examples**: Added for each API request to make it easier for review and setup. 17 | - **HTML Reports**: Generated for test execution tracking and reporting. 18 | 19 | 20 | ![napkin-selection (10)](https://github.com/user-attachments/assets/06471db4-c847-42a8-85be-04ec852dbb7b) 21 | 22 | 23 | # Project Structure 24 | 25 | The framework is organized with the following files: 26 | 27 | - **README.md**: The project's documentation. It describes the framework's purpose, features, technologies used, and how to use it. 28 | - **test_data_Create_User.csv**: A CSV (Comma Separated Values) file used for data-driven testing. It contains multiple sets of data that will be used as input for the CreateUser API request. 29 | - **Users.postman_collection.json**: The core of the framework. This JSON file contains the Postman collection. It defines all the API requests, tests, pre-request scripts, and other configurations. 30 | - **Users.postman_test_run.json**: Contains the results of a test run using Newman. It shows the test results, including pass/fail counts, response times, and other details. 31 | - **newManCommands.txt**: Contains instructions and commands for setting up and using Newman, the command-line tool for running Postman collections. 32 | - **QA.postman_environment.json**: A Postman environment file containing environment-specific variables, such as the base URL of the API. 33 | 34 | 35 | ![napkin-selection (6)](https://github.com/user-attachments/assets/dbe31e03-027a-4b84-96bc-9a312dea7252) 36 | 37 | # Core Entities within Users.postman_collection.json 38 | 39 | - **info**: Contains metadata about the collection, such as its name, ID, and schema. 40 | 41 | - **item**: An array of API requests (also called "items"). Each item represents a specific API endpoint and its associated tests and configurations. 42 | 43 | - **name**: The name of the API request (e.g., "GetAllUsers", "CreateUser"). 44 | 45 | - **event**: An array of events that can be triggered at different stages of the request lifecycle. 46 | 47 | - **listen**: Specifies when the script should run (e.g., "test" for after the response is received, "prerequest" for before the request is sent). 48 | 49 | - **script**: Contains the JavaScript code to be executed. 50 | 51 | - **exec**: An array of strings, each representing a line of JavaScript code. 52 | - **type**: The script type (usually "text/javascript"). 53 | 54 | - **request**: Defines the API request itself. 55 | 56 | - **method**: The HTTP method (e.g., "GET", "POST", "PUT"). 57 | 58 | - **header**: An array of HTTP headers. 59 | 60 | - **body**: The request body (for POST, PUT, etc.). 61 | 62 | - **mode**: The format of the body (e.g., "raw", "formdata"). 63 | - **raw**: The raw body content. 64 | - **options**: Options for the body, such as the language ("json"). 65 | 66 | - **url**: The API endpoint URL. 67 | 68 | - **raw**: The complete URL. 69 | - **host**: The base URL. 70 | - **path**: The path segments. 71 | - **query**: Query parameters. 72 | 73 | - **response**: Contains example responses for the request. These are for documentation and preview purposes within Postman. They are not used during automated test execution by Newman. 74 | 75 | - **event (Collection-level)**: Similar to item-level events, but these apply to the entire collection. 76 | 77 | 78 | 79 | 80 | ![napkin-selection (7)](https://github.com/user-attachments/assets/8244502f-7024-4d21-abe9-c2f0c3ba9cb9) 81 | 82 | # Key Concepts and Technologies 83 | 84 | - **Postman**: A popular API development and testing tool. It provides a graphical interface for creating and sending HTTP requests, as well as writing tests and managing collections. 85 | 86 | - **Newman**: A command-line tool for running Postman collections. It allows you to automate API tests as part of a CI/CD pipeline. 87 | 88 | - **JavaScript**: The scripting language used in Postman tests and pre-request scripts. 89 | 90 | - **Data-Driven Testing**: A testing technique where test data is stored in a separate file (like the CSV file here) and used to run the same test multiple times with different inputs. 91 | 92 | - **Pre-request Scripts**: JavaScript code that runs before a request is sent. These are used for tasks like setting variables, generating authentication tokens, or modifying the request. 93 | 94 | - **Tests (Post-request scripts)**: JavaScript code that runs after a response is received. These are used to validate the response status code, body content, headers, and other aspects of the response. 95 | 96 | - **Collection Variables**: Variables that are defined at the collection level and can be accessed by all requests and scripts within the collection. 97 | 98 | - **Environment Variables**: Variables that are defined in an environment file and can be used to configure tests for different environments (e.g., development, testing, production). 99 | 100 | ![napkin-selection (8)](https://github.com/user-attachments/assets/bc31e49f-50f2-4757-b7e5-d9aeb96eef72) 101 | 102 | # Workflow 103 | 104 | - The API requests, tests, and configurations are defined in the **Users.postman_collection.json** file using Postman. 105 | 106 | - Test data is stored in **test_data_Create_User.csv**. 107 | 108 | - Environment-specific variables are stored in **QA.postman_environment.json**. 109 | 110 | - **Newman** is used to run the collection from the command line, using the following command (as shown in **newManCommands.txt**): 111 | 112 | ```bash 113 | newman run Users.postman_collection.json -d test_data_Create_User.csv -e QA.postman_environment.json 114 | 115 | ''' 116 | 117 | ![napkin-selection (9)](https://github.com/user-attachments/assets/ed79423d-2d0b-4172-b95c-580a20d5282f) 118 | -------------------------------------------------------------------------------- /Users.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "8d847ba4-63e8-42ff-aeed-ad9096f69396", 4 | "name": "Users", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", 6 | "_exporter_id": "20630078" 7 | }, 8 | "item": [ 9 | { 10 | "name": "GetAllUsers", 11 | "event": [ 12 | { 13 | "listen": "test", 14 | "script": { 15 | "exec": [ 16 | "const jsonData = pm.response.json();\r", 17 | "var totalEntriesPerPage = 12;\r", 18 | "var expectedStatusCode = 200;\r", 19 | "\r", 20 | "pm.test(\"Validate status code is 200\", \r", 21 | "function() {\r", 22 | " pm.response.to.have.status(expectedStatusCode);\r", 23 | "});\r", 24 | "\r", 25 | "pm.test(\"Validate request has property Page and page number is as per request\", \r", 26 | "function(){\r", 27 | " pm.expect(jsonData).have.property(\"page\");\r", 28 | " pm.expect(jsonData.page).to.eql(parseInt(pm.collectionVariables.get(\"getAllUsers\")));\r", 29 | " console.log(\"Json data: \"+jsonData.page);\r", 30 | " console.log(\"Collection variable: \"+parseInt(pm.collectionVariables.get(\"getAllUsers\")));\r", 31 | "});\r", 32 | "\r", 33 | "pm.test(\"Validate per page entry and total entries\",\r", 34 | "function(){\r", 35 | " pm.expect(jsonData.total).to.eql(totalEntriesPerPage);\r", 36 | " pm.expect(jsonData.total_pages).to.eql(parseInt(pm.collectionVariables.get(\"getAllUsers\")));\r", 37 | "});\r", 38 | "\r", 39 | "postman.setNextRequest(\"CreateUser\");" 40 | ], 41 | "type": "text/javascript" 42 | } 43 | } 44 | ], 45 | "request": { 46 | "method": "GET", 47 | "header": [], 48 | "url": { 49 | "raw": "{{base_url}}/api/users?page={{getAllUsers}}", 50 | "host": [ 51 | "{{base_url}}" 52 | ], 53 | "path": [ 54 | "api", 55 | "users" 56 | ], 57 | "query": [ 58 | { 59 | "key": "page", 60 | "value": "{{getAllUsers}}" 61 | } 62 | ] 63 | } 64 | }, 65 | "response": [ 66 | { 67 | "name": "GetAllBooks", 68 | "originalRequest": { 69 | "method": "GET", 70 | "header": [], 71 | "url": { 72 | "raw": "{{base_url}/api/users", 73 | "host": [ 74 | "{{base_url}" 75 | ], 76 | "path": [ 77 | "api", 78 | "users" 79 | ], 80 | "query": [ 81 | { 82 | "key": "page", 83 | "value": "2", 84 | "disabled": true 85 | } 86 | ] 87 | } 88 | }, 89 | "_postman_previewlanguage": null, 90 | "header": null, 91 | "cookie": [], 92 | "body": "{\r\n \"page\": 2,\r\n \"per_page\": 6,\r\n \"total\": 12,\r\n \"total_pages\": 2,\r\n \"data\": [\r\n {\r\n \"id\": 7,\r\n \"email\": \"michael.lawson@reqres.in\",\r\n \"first_name\": \"Michael\",\r\n \"last_name\": \"Lawson\",\r\n \"avatar\": \"https://reqres.in/img/faces/7-image.jpg\"\r\n }\r\n ],\r\n \"support\": {\r\n \"url\": \"https://reqres.in/#support-heading\",\r\n \"text\": \"To keep ReqRes free, contributions towards server costs are appreciated!\"\r\n }\r\n}" 93 | } 94 | ] 95 | }, 96 | { 97 | "name": "CreateUser", 98 | "event": [ 99 | { 100 | "listen": "test", 101 | "script": { 102 | "exec": [ 103 | "//JsonFormatter - https://jsonformatter.org/json-to-jsonschema \r", 104 | "//You need to customize the schema as per your requirement (You can see a example below)\r", 105 | "\r", 106 | "const schema = {\r", 107 | " \"type\": \"object\",\r", 108 | " \"additionalProperties\": false,\r", 109 | " \"properties\": {\r", 110 | " \"name\": {\r", 111 | " \"type\": \"string\"\r", 112 | " },\r", 113 | " \"job\": {\r", 114 | " \"type\": \"string\"\r", 115 | " },\r", 116 | " \"id\": {\r", 117 | " \"type\": \"string\"\r", 118 | " },\r", 119 | " \"createdAt\": {\r", 120 | " \"type\": \"string\",\r", 121 | " \"format\": \"date-time\"\r", 122 | " }\r", 123 | " },\r", 124 | " \"required\": [\r", 125 | " \"createdAt\",\r", 126 | " \"id\",\r", 127 | " \"job\",\r", 128 | " \"name\"\r", 129 | " ]\r", 130 | " };\r", 131 | "\r", 132 | " const jsonData = pm.response.json(); \r", 133 | "\r", 134 | "pm.test(\"Validate the Json Schema\",\r", 135 | "function(){\r", 136 | " pm.response.to.have.jsonSchema(schema);\r", 137 | "});\r", 138 | "\r", 139 | "pm.test(\"Validate the username are correct\",\r", 140 | "function(){\r", 141 | " pm.expect(pm.collectionVariables.get(\"userName\")).to.eql(jsonData.name);\r", 142 | "});\r", 143 | "\r", 144 | "pm.test(\"Validate the job description is correct\", \r", 145 | "function(){\r", 146 | " pm.expect(pm.collectionVariables.get(\"job\")).to.eql(jsonData.job);\r", 147 | "});\r", 148 | "\r", 149 | "pm.collectionVariables.set(\"getUserID\", jsonData.id);\r", 150 | "\r", 151 | "//setNext request is for demo purpose (it does not work because API uses demo server - which does not save POST data)\r", 152 | "postman.setNextRequest(\"GetUser\");\r", 153 | "" 154 | ], 155 | "type": "text/javascript" 156 | } 157 | }, 158 | { 159 | "listen": "prerequest", 160 | "script": { 161 | "exec": [ 162 | "pm.collectionVariables.set(\"userName\", pm.iterationData.get(\"UserName\"));\r", 163 | "console.log(pm.collectionVariables.get(\"userName\"));\r", 164 | "\r", 165 | "pm.collectionVariables.set(\"job\", pm.iterationData.get(\"Job\"));\r", 166 | "console.log(pm.collectionVariables.get(\"job\"));" 167 | ], 168 | "type": "text/javascript" 169 | } 170 | } 171 | ], 172 | "request": { 173 | "method": "POST", 174 | "header": [], 175 | "body": { 176 | "mode": "raw", 177 | "raw": "{\r\n \"name\": \"{{userName}}\",\r\n \"job\": \"{{job}}\"\r\n}", 178 | "options": { 179 | "raw": { 180 | "language": "json" 181 | } 182 | } 183 | }, 184 | "url": { 185 | "raw": "{{base_url}}/api/users", 186 | "host": [ 187 | "{{base_url}}" 188 | ], 189 | "path": [ 190 | "api", 191 | "users" 192 | ] 193 | } 194 | }, 195 | "response": [ 196 | { 197 | "name": "CreateUser", 198 | "originalRequest": { 199 | "method": "POST", 200 | "header": [], 201 | "body": { 202 | "mode": "raw", 203 | "raw": "{\r\n \"name\": \"morpheus\",\r\n \"job\": \"leader\"\r\n}", 204 | "options": { 205 | "raw": { 206 | "language": "json" 207 | } 208 | } 209 | }, 210 | "url": { 211 | "raw": "https://reqres.in/api/users", 212 | "protocol": "https", 213 | "host": [ 214 | "reqres", 215 | "in" 216 | ], 217 | "path": [ 218 | "api", 219 | "users" 220 | ] 221 | } 222 | }, 223 | "_postman_previewlanguage": null, 224 | "header": null, 225 | "cookie": [], 226 | "body": "{\r\n \"name\": \"string\",\r\n \"job\": \"string\",\r\n \"id\": \"string\",\r\n \"createdAt\": \"2022-11-15T05:32:21.322Z\"\r\n}" 227 | } 228 | ] 229 | }, 230 | { 231 | "name": "GetUser", 232 | "event": [ 233 | { 234 | "listen": "test", 235 | "script": { 236 | "exec": [ 237 | "//tests similar to GetAllUsers and CreateUser can be created for this as well" 238 | ], 239 | "type": "text/javascript" 240 | } 241 | } 242 | ], 243 | "request": { 244 | "method": "GET", 245 | "header": [], 246 | "url": { 247 | "raw": "{{base_url}}/api/users/{{getUserID}}", 248 | "host": [ 249 | "{{base_url}}" 250 | ], 251 | "path": [ 252 | "api", 253 | "users", 254 | "{{getUserID}}" 255 | ] 256 | } 257 | }, 258 | "response": [ 259 | { 260 | "name": "GetUser", 261 | "originalRequest": { 262 | "method": "GET", 263 | "header": [ 264 | { 265 | "key": "", 266 | "value": "", 267 | "type": "text", 268 | "disabled": true 269 | } 270 | ], 271 | "url": { 272 | "raw": "https://reqres.in/api/users/1", 273 | "protocol": "https", 274 | "host": [ 275 | "reqres", 276 | "in" 277 | ], 278 | "path": [ 279 | "api", 280 | "users", 281 | "1" 282 | ], 283 | "query": [ 284 | { 285 | "key": "", 286 | "value": null, 287 | "disabled": true 288 | } 289 | ] 290 | } 291 | }, 292 | "_postman_previewlanguage": null, 293 | "header": null, 294 | "cookie": [], 295 | "body": "{\r\n \"data\": {\r\n \"id\": 1,\r\n \"email\": \"george.bluth@reqres.in\",\r\n \"first_name\": \"George\",\r\n \"last_name\": \"Bluth\",\r\n \"avatar\": \"https://reqres.in/img/faces/1-image.jpg\"\r\n },\r\n \"support\": {\r\n \"url\": \"https://reqres.in/#support-heading\",\r\n \"text\": \"To keep ReqRes free, contributions towards server costs are appreciated!\"\r\n }\r\n}" 296 | } 297 | ] 298 | }, 299 | { 300 | "name": "UpdateUser", 301 | "event": [ 302 | { 303 | "listen": "test", 304 | "script": { 305 | "exec": [ 306 | "//tests similar to GetAllUsers and CreateUser can be created for this as well" 307 | ], 308 | "type": "text/javascript" 309 | } 310 | } 311 | ], 312 | "request": { 313 | "method": "PUT", 314 | "header": [], 315 | "body": { 316 | "mode": "raw", 317 | "raw": "{\r\n \"name\": \"{{updated_userName}}\",\r\n \"job\": \"{{job}}\"\r\n}", 318 | "options": { 319 | "raw": { 320 | "language": "json" 321 | } 322 | } 323 | }, 324 | "url": { 325 | "raw": "{{base_url}}/api/users/{{updateUserID}}", 326 | "host": [ 327 | "{{base_url}}" 328 | ], 329 | "path": [ 330 | "api", 331 | "users", 332 | "{{updateUserID}}" 333 | ] 334 | } 335 | }, 336 | "response": [ 337 | { 338 | "name": "UpdateUser", 339 | "originalRequest": { 340 | "method": "PUT", 341 | "header": [], 342 | "body": { 343 | "mode": "raw", 344 | "raw": "{\r\n \"name\": \"Jason\",\r\n \"job\": \"zion resident\"\r\n}", 345 | "options": { 346 | "raw": { 347 | "language": "json" 348 | } 349 | } 350 | }, 351 | "url": { 352 | "raw": "https://reqres.in/api/users/1", 353 | "protocol": "https", 354 | "host": [ 355 | "reqres", 356 | "in" 357 | ], 358 | "path": [ 359 | "api", 360 | "users", 361 | "1" 362 | ] 363 | } 364 | }, 365 | "_postman_previewlanguage": null, 366 | "header": null, 367 | "cookie": [], 368 | "body": "{\r\n \"name\": \"Jason\",\r\n \"job\": \"zion resident\",\r\n \"updatedAt\": \"2022-11-15T05:41:35.558Z\"\r\n}" 369 | } 370 | ] 371 | }, 372 | { 373 | "name": "RegisterUser", 374 | "request": { 375 | "method": "POST", 376 | "header": [], 377 | "body": { 378 | "mode": "raw", 379 | "raw": "{\r\n \"email\": \"{{email}}\",\r\n \"password\": \"{{register_password}}\"\r\n}", 380 | "options": { 381 | "raw": { 382 | "language": "json" 383 | } 384 | } 385 | }, 386 | "url": { 387 | "raw": "{{base_url}}/api/register", 388 | "host": [ 389 | "{{base_url}}" 390 | ], 391 | "path": [ 392 | "api", 393 | "register" 394 | ] 395 | } 396 | }, 397 | "response": [ 398 | { 399 | "name": "RegisterUser-Correct User", 400 | "originalRequest": { 401 | "method": "POST", 402 | "header": [], 403 | "body": { 404 | "mode": "raw", 405 | "raw": "{\r\n \"email\": \"eve.holt@reqres.in\",\r\n \"password\": \"pistol\"\r\n}", 406 | "options": { 407 | "raw": { 408 | "language": "json" 409 | } 410 | } 411 | }, 412 | "url": { 413 | "raw": "https://reqres.in/api/register", 414 | "protocol": "https", 415 | "host": [ 416 | "reqres", 417 | "in" 418 | ], 419 | "path": [ 420 | "api", 421 | "register" 422 | ] 423 | } 424 | }, 425 | "_postman_previewlanguage": null, 426 | "header": null, 427 | "cookie": [], 428 | "body": "{\r\n \"id\": 4,\r\n \"token\": \"QpwL5tke4Pnpja7X4\"\r\n}" 429 | } 430 | ] 431 | }, 432 | { 433 | "name": "RegisterUser - MissingPswd", 434 | "event": [ 435 | { 436 | "listen": "test", 437 | "script": { 438 | "exec": [ 439 | "var jsonResponse = pm.response.json();\r", 440 | "var errorMessage = \"Missing password\";\r", 441 | "const jsonSchema = {\r", 442 | " \"type\": \"object\",\r", 443 | " \"additionalProperties\": false,\r", 444 | " \"properties\": {\r", 445 | " \"error\": {\r", 446 | " \"type\": \"string\"\r", 447 | " }\r", 448 | " },\r", 449 | " \"required\": [\r", 450 | " \"error\"\r", 451 | " ]\r", 452 | " };\r", 453 | "\r", 454 | "pm.test(\"Validate the json schema\", \r", 455 | "function(){\r", 456 | " pm.response.to.have.jsonSchema(jsonResponse);\r", 457 | "});\r", 458 | "\r", 459 | "pm.test(\"Validate the error message\", \r", 460 | "function(){\r", 461 | " pm.expect(jsonResponse.error).to.eql(errorMessage);\r", 462 | "});" 463 | ], 464 | "type": "text/javascript" 465 | } 466 | } 467 | ], 468 | "request": { 469 | "method": "POST", 470 | "header": [], 471 | "body": { 472 | "mode": "raw", 473 | "raw": "{\r\n \"email\": \"{{email}}\"\r\n}", 474 | "options": { 475 | "raw": { 476 | "language": "json" 477 | } 478 | } 479 | }, 480 | "url": { 481 | "raw": "{{base_url}}/api/register", 482 | "host": [ 483 | "{{base_url}}" 484 | ], 485 | "path": [ 486 | "api", 487 | "register" 488 | ] 489 | } 490 | }, 491 | "response": [ 492 | { 493 | "name": "RegisterUser - Missing Password", 494 | "originalRequest": { 495 | "method": "POST", 496 | "header": [], 497 | "body": { 498 | "mode": "raw", 499 | "raw": "{\r\n \"email\": \"eve.holt@reqres.in\",\r\n \"password\": \"pistol\"\r\n}", 500 | "options": { 501 | "raw": { 502 | "language": "json" 503 | } 504 | } 505 | }, 506 | "url": { 507 | "raw": "{{base_url}}/api/register", 508 | "host": [ 509 | "{{base_url}}" 510 | ], 511 | "path": [ 512 | "api", 513 | "register" 514 | ] 515 | } 516 | }, 517 | "_postman_previewlanguage": null, 518 | "header": null, 519 | "cookie": [], 520 | "body": "{\r\n \"error\": \"Missing password\"\r\n}" 521 | } 522 | ] 523 | }, 524 | { 525 | "name": "LoginUser", 526 | "request": { 527 | "method": "POST", 528 | "header": [], 529 | "body": { 530 | "mode": "raw", 531 | "raw": "{\r\n \"email\": \"{{email}}\",\r\n \"password\": \"{{login_password}}\"\r\n}", 532 | "options": { 533 | "raw": { 534 | "language": "json" 535 | } 536 | } 537 | }, 538 | "url": { 539 | "raw": "{{base_url}}/api/login", 540 | "host": [ 541 | "{{base_url}}" 542 | ], 543 | "path": [ 544 | "api", 545 | "login" 546 | ] 547 | } 548 | }, 549 | "response": [ 550 | { 551 | "name": "LoginUser", 552 | "originalRequest": { 553 | "method": "POST", 554 | "header": [], 555 | "body": { 556 | "mode": "raw", 557 | "raw": "{\r\n \"email\": \"eve.holt@reqres.in\",\r\n \"password\": \"pistol\"\r\n}", 558 | "options": { 559 | "raw": { 560 | "language": "json" 561 | } 562 | } 563 | }, 564 | "url": { 565 | "raw": "https://reqres.in/api/register", 566 | "protocol": "https", 567 | "host": [ 568 | "reqres", 569 | "in" 570 | ], 571 | "path": [ 572 | "api", 573 | "register" 574 | ] 575 | } 576 | }, 577 | "_postman_previewlanguage": null, 578 | "header": null, 579 | "cookie": [], 580 | "body": "{\r\n \"token\": \"QpwL5tke4Pnpja7X4\"\r\n}" 581 | } 582 | ] 583 | }, 584 | { 585 | "name": "LoginUser MissingPswd", 586 | "event": [ 587 | { 588 | "listen": "test", 589 | "script": { 590 | "exec": [ 591 | "const jsonResponse = pm.response.json();\r", 592 | "const errorMsg = \"Missing password\";\r", 593 | "\r", 594 | "pm.test(\"Validate the error message\", \r", 595 | "function(){\r", 596 | " pm.expect(jsonResponse.error).to.eql(errorMsg);\r", 597 | "});\r", 598 | "\r", 599 | "" 600 | ], 601 | "type": "text/javascript" 602 | } 603 | } 604 | ], 605 | "request": { 606 | "method": "POST", 607 | "header": [], 608 | "body": { 609 | "mode": "raw", 610 | "raw": "{\r\n \"email\": \"{{email}}\"\r\n}", 611 | "options": { 612 | "raw": { 613 | "language": "json" 614 | } 615 | } 616 | }, 617 | "url": { 618 | "raw": "{{base_url}}/api/login", 619 | "host": [ 620 | "{{base_url}}" 621 | ], 622 | "path": [ 623 | "api", 624 | "login" 625 | ] 626 | } 627 | }, 628 | "response": [ 629 | { 630 | "name": "LoginUser", 631 | "originalRequest": { 632 | "method": "POST", 633 | "header": [], 634 | "body": { 635 | "mode": "raw", 636 | "raw": "{\r\n \"email\": \"eve.holt@reqres.in\",\r\n \"password\": \"pistol\"\r\n}", 637 | "options": { 638 | "raw": { 639 | "language": "json" 640 | } 641 | } 642 | }, 643 | "url": { 644 | "raw": "{{base_url}}/api/register", 645 | "host": [ 646 | "{{base_url}}" 647 | ], 648 | "path": [ 649 | "api", 650 | "register" 651 | ] 652 | } 653 | }, 654 | "_postman_previewlanguage": null, 655 | "header": null, 656 | "cookie": [], 657 | "body": "{\r\n \"error\": \"Missing password\"\r\n}" 658 | } 659 | ] 660 | } 661 | ], 662 | "event": [ 663 | { 664 | "listen": "prerequest", 665 | "script": { 666 | "type": "text/javascript", 667 | "exec": [ 668 | "" 669 | ] 670 | } 671 | }, 672 | { 673 | "listen": "test", 674 | "script": { 675 | "type": "text/javascript", 676 | "exec": [ 677 | "" 678 | ] 679 | } 680 | } 681 | ], 682 | "variable": [ 683 | { 684 | "key": "userName", 685 | "value": "James", 686 | "type": "string" 687 | }, 688 | { 689 | "key": "job", 690 | "value": "leader", 691 | "type": "string" 692 | }, 693 | { 694 | "key": "updated_userName", 695 | "value": "Michael", 696 | "type": "string" 697 | }, 698 | { 699 | "key": "email", 700 | "value": "eve.holt@reqres.in", 701 | "type": "string" 702 | }, 703 | { 704 | "key": "register_password", 705 | "value": "pistol", 706 | "type": "string" 707 | }, 708 | { 709 | "key": "login_password", 710 | "value": "cityslicka", 711 | "type": "string" 712 | }, 713 | { 714 | "key": "getUserID", 715 | "value": "5", 716 | "type": "string" 717 | }, 718 | { 719 | "key": "updateUserID", 720 | "value": "2", 721 | "type": "string" 722 | }, 723 | { 724 | "key": "getAllUsers", 725 | "value": "2", 726 | "type": "string" 727 | } 728 | ] 729 | } -------------------------------------------------------------------------------- /Users.postman_test_run.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "6b647ca4-d224-493c-a48e-aba8095f96bb", 3 | "name": "Users", 4 | "timestamp": "2022-11-15T08:45:34.170Z", 5 | "collection_id": "20630078-8d847ba4-63e8-42ff-aeed-ad9096f69396", 6 | "folder_id": 0, 7 | "environment_id": "20630078-c5c74082-0432-4eed-a32d-28fd15d5a010", 8 | "totalPass": 15, 9 | "totalFail": 0, 10 | "results": [ 11 | { 12 | "id": "902f8807-7d5d-4a13-91c8-72d3056c19ec", 13 | "name": "CreateUser", 14 | "time": 319, 15 | "responseCode": { 16 | "code": 201, 17 | "name": "Created" 18 | }, 19 | "tests": { 20 | "Validate the Json Schema": true, 21 | "Validate the username are correct": true, 22 | "Validate the job description is correct": true 23 | }, 24 | "testPassFailCounts": { 25 | "Validate the Json Schema": { 26 | "pass": 5, 27 | "fail": 0 28 | }, 29 | "Validate the username are correct": { 30 | "pass": 5, 31 | "fail": 0 32 | }, 33 | "Validate the job description is correct": { 34 | "pass": 5, 35 | "fail": 0 36 | } 37 | }, 38 | "times": [ 39 | 424, 40 | 314, 41 | 299, 42 | 341, 43 | 319 44 | ], 45 | "allTests": [ 46 | { 47 | "Validate the Json Schema": true, 48 | "Validate the username are correct": true, 49 | "Validate the job description is correct": true 50 | }, 51 | { 52 | "Validate the Json Schema": true, 53 | "Validate the username are correct": true, 54 | "Validate the job description is correct": true 55 | }, 56 | { 57 | "Validate the Json Schema": true, 58 | "Validate the username are correct": true, 59 | "Validate the job description is correct": true 60 | }, 61 | { 62 | "Validate the Json Schema": true, 63 | "Validate the username are correct": true, 64 | "Validate the job description is correct": true 65 | }, 66 | { 67 | "Validate the Json Schema": true, 68 | "Validate the username are correct": true, 69 | "Validate the job description is correct": true 70 | } 71 | ] 72 | } 73 | ], 74 | "count": 5, 75 | "totalTime": 1697, 76 | "collection": { 77 | "requests": [ 78 | { 79 | "id": "902f8807-7d5d-4a13-91c8-72d3056c19ec", 80 | "method": "POST" 81 | } 82 | ] 83 | } 84 | } -------------------------------------------------------------------------------- /newManCommands.txt: -------------------------------------------------------------------------------- 1 | commands for setting up newman (postman) 2 | 3 | To install newman = 4 | npm install -g newman 5 | 6 | How to execute the Collection from Postman using Newman? 7 | 8 | 1) Export your collection as json and store it in your local system 9 | 2) You can get a public link (By clicking on share button) and then using that link - you can directly 10 | execute your script 11 | 12 | Let's execute with 1 - 13 | newman run -d -e 14 | -g 15 | Note - No spaces should be there in your fileNames 16 | Example = 17 | newman run Users.postman_collection.json -d test_data_Create_User.csv -e QA.postman_environment.json -------------------------------------------------------------------------------- /test_data_Create_User.csv: -------------------------------------------------------------------------------- 1 | UserName,Job 2 | James,Leader 3 | Jason,Servant 4 | Michael,Driver 5 | Mitchell,Cook 6 | Cristal,Professor --------------------------------------------------------------------------------