POSTMAN
more than what meets the eye
- Ritesh Ranjan
What's the talk about
- Features overview in Postman
- Scripting in Postman
- Writing Test Cases for API
- Writing Integration Test
- Pros and Cons
- Comparisons
Collections & Folders
- Easy way to group and share a collection of APIs
- Provides scripting features in a Collection / Folder.
- Collection can used to Run a API integration test.
{{Variables}}
- Helps you to keep your code DRY
Scopes
- Global
- Collection
- Environment
- Local
- Data
// Set variables
pm.environment.set("url", "www.google.com")
pm.global.set("url", "www.google.com")
// Get variables
pm.variables.get("url")
pm.environment.get("url")
pm.global.get("url")
Environment and Global
- Set of key-value pairs
- Can be exported and Shared
Scripting
- Powerful runtime based on Node.js
- Can add dynamic behavior to requests and collections
JavaScript code to execute during 2 events in the flow
- Pre-request script
- Test script under the Tests tab
Postman Sandbox
- JavaScript execution environment
- Code you write in the pre-request/test script section is executed in this sandbox.
- Supported libs: here
Detailed Execution Order
Pre-request script
- Js Scripts executed before a Test is Run
- Can be added to a Collection, Folder or a Request
- Default Sandbox Runtime of Postman is Available
// Prefix
var prefix = "mdl_heroku_";
// Clear global variables
pm.globals.unset(prefix + "sessionToken");
// Set a random user name
pm.globals.set(prefix + "userName", "Perf_rit_" + prefix + Date.now() + "@hello.mileiq.com");
Test Script
- JavaScript code executed after the request is sent
- Access to the pm.response
- Can be added to Collection, Folder and Test
// example using pm.response.to.have
pm.test("response is ok", function () {
pm.response.to.have.status(200);
});
Condition Flow
- postman.setNextRequest("request_name")
// Set the request to be executed next
pm.setNextRequest("request_name");
// Stop workflow execution
pm.setNextRequest(null);
Collection Run
- Groups of requests that can be run together as a series of requests
- Can be run against an environment
- Used to build integration test suites
- Can pass data between API requests
- Can have conditional flows
- Can also use CSV data file
DEMO
Pros
- Already most used API testing tool for devs
- Good way to publish sample request
- No need to learn new scripting
- Natural for most devs to write in JS
- Can be easly integrated with CI/CD using newman
newman run postman-config/MDL_Rest_Login_Flow_Automated.postman_collection.json
-e postman-config/Actual_Router_Perf.postman_environment.json
--exitCode 1
Comparisons
- Similar Desktop based Tools
- Cloud based
Cons
- Including custom js libraries sandbox is hacky.
- No easy way to call API of different collection.
- Custom script to connect to DB is difficult (hacky way)
- Cannot be used as Load testing
- Difficult to have Code Reviews and Pull Requests as collections are stored as JSON files.
- No Direct GIT integration like Soap UI
Questions
POSTMAN
By ritesh ranjan
POSTMAN
- 188