-
-
Save kool79/9a3fffd6d3db0c5ba998b7fbc970d1f9 to your computer and use it in GitHub Desktop.
Saving JavaScript code to a variable in Postman
This file contains 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