postman安装与简要操作( 三 )


文章插图
 
2.用console.log()打印,到控制台看
console.log(jsondata.access_token);
3.tests['这里拼出你想看的字符串']= true在界面/报告看断言
tests[jsondata.access_token] = false;
7、定义公共函数
常用公共函数:
1).判断是否超时(assertNotTimeout):
varhasResponse=postman.getResponseHeader('Content-Type')?true:false;if(!hasResponse) tests['服务端在超时前没返回任何数据,请检查相关服务、网络或反向代理设置(以下跳过其他断言)']=false;
2).未超时,显示发出的请求参数(logParams):
if(hasResponse) tests[`[INFO] 请求参数(超时没返回时不解析):${JSON.stringify(request.data)}`]=true;
3).未超时,解析返回的JSON对象(getResponseJson):
try{if(hasResponse) var json=JSON.parse(responseBody);}catch(err){tests['服务端没返回合法的JSON格式,请检查相关服务、网络或反向代理设置(以下跳过其他断言)']=false; tests[`[INFO] 返回:${responseBody}`]=true;console.error(err);}
4).返回元素的类型(assertType):
var assertType=(name,value,type)=>{letisType=(type==='array')? Array.isArray(value):typeof value=https://www.isolves.com/it/cxkf/bk/2019-09-27/==type;tests[`${name}为${type}(实际值:${value})`]=isType;};
js的数据类型:
typeof 2 输出 number
typeof null 输出 object
typeof {} 输出 object
typeof [] 输出 object
typeof (function(){}) 输出 function
typeof undefined 输出 undefined
typeof '222' 输出 string
typeof true 输出 boolean
5).返回元素是否与预期值一致(assertEqual):
var assertEqual=(name,actual,expected)=>{tests[`${name}等于${expected}(实际值:${actual})`]=actual===expected;};
6).返回元素是否与预期值不一致(assertNotEqual):
varassertNotEqual=(name,actual,expected)=>{tests[`${name}不等于${expected}(实际值:${actual})`]=actual!==expected;};
————————————————
版权声明:本文为CSDN博主「快乐风男灬」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明 。
原文链接:https://blog.csdn.net/q386815991/article/details/79569409




推荐阅读