• postman常用公共函数


    常用公共函数:

    1).判断是否超时(assertNotTimeout):
    var hasResponse=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)=>{let isType=(type==='array')? Array.isArray(value):typeof value===type; tests[`${name}为${type}(实际值:${value})`]=isType;};

    5).返回元素是否与预期值一致(assertEqual):
    var assertEqual=(name,actual,expected)=>{tests[`${name}等于${expected}(实际值:${actual})`]=actual===expected;};

    6).返回元素是否与预期值不一致(assertNotEqual):
    var assertNotEqual=(name,actual,expected)=>{tests[`${name}不等于${expected}(实际值:${actual})`]=actual!==expected;};

  • 相关阅读:
    IOS
    XCode
    Android Studio
    Android Studio
    Cordova
    Delphi
    Cordova
    Delphi
    JQuery Mobile
    twitter ads_campaign management(图示)
  • 原文地址:https://www.cnblogs.com/Zcxxf/p/6655138.html
Copyright © 2020-2023  润新知