Postman Cheetsheet
Postman Cheetsheet
Any variable type Partial body match / body contains: Postman Echo
pm.variables.get("myVariable");
External libraries pm.expect(pm.response.text())
.to.include("Order placed."); Helper API for testing requests. Read more at:
https://docs.postman-echo.com.
in the request builder tv4 - JSON schema validator JSON responses
Syntax: {{myVariable}} var jsonSchema = { "items": { "type": "boolean" }}; Get Current UTC time in pre-request script:
var jsonData1 = [true, false]; Parse body (need for all assertions):
Request URL: http://{{domain}}/users/{{userId}} var jsonData2 = [true, "John"]; var jsonData = pm.response.json(); pm.sendRequest('https://postman-
echo.com/time/now', function (err, res) {
Headers (key, value): X-{{myHeaderName}} pm.test('Schema is valid', function() { Simple value check: if (err) { console.log(err); }
pm.expect(tv4.validate(data1, schema)) pm.expect(jsonData.age).to.eql(30); else {
Body: { "id": "{{userId}}”, "name": "John Doe”} .to.be.true; pm.expect(jsonData.name).to.eql("John"); var currentTime = res.stream.toString();
pm.expect(tv4.validate(data2, schema)) console.log(currentTime);
REMOVING .to.be.true; pm.environment.set("currentTime", currentTime);
Nested value check: }});
console.log("Validation failed: ", tv4.error); pm.expect(jsonData. products.0.category)
Global }); .to.eql(”Detergent");
pm.globals.unset("myVariable"); XML responses
pm.globals.clear(); CryptoJS - cryptographic algorithms Convert XML body to JSON:
Generate SHA-1 hash: var jsonData = xml2Json(responseBody);
Environment
CryptoJS.SHA1("Message").toString(); Note: see assertions for JSON responses.
pm.environment.unset("myVariable");
pm.environment.clear();
The Postman logo and name are property of Postdot Technologies, Inc. • CC BY Valentin Despa • valentin@vdespa.com • www.vdespa.com • Version 0.2.0 • Updated: 2018-02