Tip #5 in the below list:
http://blog.getpostman.com/2017/07/28/api-testing-tips-from-a-postman-professional/
- Init in Pre-Request or Tests tab or in a previous request.
- Store in an Environment or Global variable.
- Then call multiple times from other requests.
postman.setEnvironmentVariable("commonTests", (responseBody, environmentSchema) => { // parse response and log var responseObject = JSON.parse(responseBody); //console.log("response: " + JSON.stringify(responseObject)); // test to check status code tests["Status code is 200"] = responseCode.code === 200; // test response time console.log("responseTime: " + responseTime); tests["Response time is less than " + environment.max_server_response_time + "ms"] = responseTime < environment.max_server_response_time; // validate schema eval(environment.validateSchema)(responseObject, environmentSchema); });
2) Call method from the Pre-Request or Tests tab in Postman.
You can also call methods from within another method as you can see at the end of the previous code sample.
// validate schema eval(environment.commonTests)(responseObject, environment.specificSchema);
0 comments:
Post a Comment