溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

postman內(nèi)置腳本說明

發(fā)布時間:2020-06-06 13:22:28 來源:網(wǎng)絡(luò) 閱讀:916 作者:32氪 欄目:建站服務(wù)器

.內(nèi)置腳本說明

 1. 清除一個全局變量
     Clear a global variable
    對應(yīng)腳本:
    postman.clearGlobalVariable("variable_key");
    參數(shù):需要清除的變量的key  2.清除一個環(huán)境變量
    Clear an environment variable
    對應(yīng)腳本:
    postman.clearEnvironmentVariable("variable_key");
    參數(shù):需要清除的環(huán)境變量的key  3.response包含內(nèi)容
    Response body:Contains string
    對應(yīng)腳本:
    tests["Body matches string"] =responseBody.has("string_you_want_to_search");
    參數(shù):預(yù)期內(nèi)容  4.將xml格式的response轉(zhuǎn)換成son格式
    Response body:Convert XML body to a JSON Object
    對應(yīng)腳本:    var jsonObject = xml2Json(responseBody);
    參數(shù):(默認(rèn)不需要設(shè)置參數(shù),為接口的response)需要轉(zhuǎn)換的xml  5.response等于預(yù)期內(nèi)容
    Response body:Is equal to a string
    對應(yīng)腳本:
    tests["Body is correct"] = responseBody === "response_body_string";
    參數(shù):預(yù)期response  6.json解析key的值進(jìn)行校驗
    Response body:JSON value check
    對應(yīng)腳本:
    tests["Args key contains argument passed as url parameter"] = 'test' in responseJSON.args
    參數(shù):test替換被測的值,args替換被測的key  7.檢查response的header信息是否有被測字段
    Response headers:Content-Type header check
    對應(yīng)腳本:
    tests["Content-Type is present"] = postman.getResponseHeader("Content-Type");
    參數(shù):預(yù)期header  8.響應(yīng)時間判斷
    Response time is less than 200ms
    對應(yīng)腳本:
    tests["Response time is less than 200ms"] = responseTime < 200;
    參數(shù):響應(yīng)時間    9.設(shè)置全局變量      Set an global variable
      對應(yīng)腳本:
      postman.setGlobalVariable("variable_key", "variable_value");
      參數(shù):全局變量的鍵值    10.設(shè)置環(huán)境變量      Set an environment variable
      對應(yīng)腳本:
      postman.setEnvironmentVariable("variable_key", "variable_value");
      參數(shù):環(huán)境變量的鍵值    11.判斷狀態(tài)碼
      Status code:Code is 200
      對應(yīng)腳本:
      tests["Status code is 200"] = responseCode.code != 400;
      參數(shù):狀態(tài)碼    12.檢查code name 是否包含內(nèi)容
      Status code:Code name has string
      對應(yīng)腳本:
      tests["Status code name has string"] = responseCode.name.has("Created");
      參數(shù):預(yù)期code name包含字符串    13.成功的post請求
      Status code:Successful POST request
      對應(yīng)腳本:
      tests["Successful POST request"] = responseCode.code === 201 || responseCode.code === 202;     14.微小驗證器
       Use Tiny Validator for JSON data            
       對應(yīng)腳本: 
        var schema = {         "items": {         "type": "boolean"
             }
         };        var data1 = [true, false];        var data2 = [true, 123];        console.log(tv4.error);
        tests["Valid Data1"] = tv4.validate(data1, schema);
        tests["Valid Data2"] = tv4.validate(data2, schema);
        參數(shù):可以修改items里面的鍵值對來對應(yīng)驗證json的參數(shù)


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI