测试脚本:
设置环境变量
var jsonData = JSON.parse(responseBody);
postman.setGlobalVariable("5KMST", jsonData.data.st);
(3).response包含内容 Response body:Contains string
对应脚本:
tests["Body matches string"] =responseBody.has("string_you_want_to_search");
参数:预期内容
(5).response等于预期内容 Response body:Is equal to a string
对应脚本:
tests["Body is correct"] = responseBody === "response_body_string";
参数:预期response
var jsonData = JSON.parse(responseBody); // 将请求的结果转化为JSON格式
tests["Your test name"] = jsonData.value === 100; // value是参数名(根据接口返回结果填写),100是response返回的值(和value对应)
(8).响应时间判断 Response time is less than 200ms
对应脚本:
tests["Response time is less than 200ms"] = responseTime < 200;
参数:响应时间
(11).判断状态码 Status code:Code is 200
对应脚本:
tests["Status code is 200"] = responseCode.code != 400;
参数:状态码
for语句的用法:
if语句用法:
if(responseCode.code !== 201){
tests["服务器报错"] = true;
}