Postman (REST Client) Tests
Published 2014-10-31, 16:04
### VORBEREITUNG ###
// save response in env
var data = responseBody;
postman.setEnvironmentVariable("data", data);
// parse value from json and save in env
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("device_id", data.id);
// parse array from json and safe as string and save in env
var data = JSON.parse(responseBody);
var product = JSON.stringify(data[0]);
postman.setEnvironmentVariable("contentful", product);
// parse array from json, change value, and safe as string and save in env
var data = JSON.parse(responseBody);
data.locale = "en_US";
var device_update = JSON.stringify(data);
postman.setEnvironmentVariable("device_update", device_update);
### TESTS ###
// test resposonse code
tests["Status code is 200"] = responseCode.code === 200;
// test if response is empty
var data = JSON.parse(responseBody);
tests["Transaction list is empty"] = data.length === 0;
// test if body contains value
tests["Body contains string" + environment.device_id] = responseBody.has(environment.device_id);
// test exact values of json
var data = JSON.parse(responseBody);
tests["transaction.id is " + environment.transaction_id] = data.id === environment.transaction_id;
tests["transaction.state is IN_PROGRESS"] = data.state === "IN_PROGRESS";
Topic(s): Notiz, Technik
No comments - :(

Zum Artikel Postman (REST Client) Tests sind noch keine Kommentare vorhanden. Deine Meinung wäre jedoch willkommen!