Created
July 27, 2017 19:23
-
-
Save JamesMessinger/bef06d26de2145bbf0a5de2addd77eaf to your computer and use it in GitHub Desktop.
Saving JavaScript code to a variable in Postman
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
// Save common tests in a global variable | |
postman.setGlobalVariable("commonTests", () => { | |
// The Content-Type must be JSON | |
tests["Content-Type header is set"] = postman.getResponseHeader("Content-Type") === "application/json"; | |
// The response time must be less than 500 milliseconds | |
tests["Response time is acceptable"] = responseTime < 500; | |
// The response body must include an "id" property | |
var data = JSON.parse(responseBody); | |
tests["Response has an ID"] = data.id !== undefined; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment