-
-
Save rproman/f44310e4ede16432663e086b271fea0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// generating random data | |
var randomData = Math.random(); | |
// getting Auth tokens from other Auth services | |
pm.sendRequest({ | |
url:"https://postman-echo.com/basic-auth", | |
method: "GET", | |
header: { | |
'Authorization': 'Basic ' + btoa('postman:password') | |
} | |
}, | |
function (err, response) { | |
pm.environment.set("token", res.json().authenticated); | |
}); | |
// obtaining request body data from another service | |
pm.sendRequest("https://postman-echo.com/get", function (err, response) { | |
var input = response.json(); | |
var jsonValue = input.headers.postman-token; | |
pm.environment.set("reqBody", jsonValue); | |
}); | |
// input validation | |
pm.test("Body matches string", function () { | |
pm.expect("input_text").to.include("input"); | |
}); | |
//assign/change postman variables | |
var randomData = Math.random(); | |
pm.environment.set("rand", randomData); | |
Test Script Snippets: | |
// output validation | |
var schema = { | |
"items": { | |
"type": "boolean" | |
} | |
}; | |
var data1 = [true, false]; | |
var data2 = [true, 123]; | |
pm.test('Schema is valid', function() { | |
pm.expect(tv4.validate(data1, schema)).to.be.true; | |
pm.expect(tv4.validate(data2, schema)).to.be.true; | |
}); | |
// variable assignment | |
pm.environment.set("aThing", "thing1"); | |
// convert data formats (xml to json) | |
// get some xml | |
var responseBody = '<?xml version="1.0"?> \ | |
<catalog> \ | |
<book id="bk101"> \ | |
<author>Gambardella, Matthew</author> \ | |
<title>XML Developer\'s Guide</title> \ | |
<genre>Computer</genre> \ | |
<price>44.95</price> \ | |
<publish_date>2000-10-01</publish_date> \ | |
<description>An in-depth look at creating applications with XML.</description> \ | |
</book> \ | |
<book id="bk102"> \ | |
<author>Ralls, Kim</author> \ | |
<title>Midnight Rain</title> \ | |
<genre>Fantasy</genre> \ | |
<price>5.95</price> \ | |
<publish_date>2000-12-16</publish_date> \ | |
<description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description> \ | |
</book> \ | |
</catalog>' | |
var jsonObject = xml2Json(responseBody); | |
// sending requests (data persistence) | |
pm.sendRequest("https://postman-echo.com/get", function (err, response) { | |
console.log(response.json()); | |
}); | |
// executing additional postman requests | |
pm.setNextRequest("POST Form Data"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment