postman常用斷言方式


 

 

 

 
postman(斷言)
一、斷言

// 斷言 =》tests

1、code is 200:斷言 http 狀態碼為 200
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    });

2、contains string:響應報文包含字符串
    pm.test("Body matches string", function () {
        pm.expect(pm.response.text()).to.include("string_you_want_to_search");
    });

3、json value check:檢查報文中的 json 值
    pm.test("Your test name", function () {
        var jsonData = pm.response.json();
        pm.expect(jsonData.value).to.eql(100);
    });

4、is equal to a string:報文等於字符串
    var res = {"code":"200","msg":"登錄成功!","model":{}}
    pm.test("Body is correct", function () {
        pm.response.to.have.body(res);
    });

5、Content Type header check:檢查報文頭中是否包含 Content Type 字段
    pm.test("Content-Type is present", function () {
        pm.response.to.have.header("Content-Type");
    });

6、response time is less than 200ms:響應時間小於 200ms
    pm.test("Response time is less than 200ms", function () {
        pm.expect(pm.response.responseTime).to.be.below(200);
    });
    
7、Successful POST request:斷言 post 請求成功,即 http 狀態碼在列表[201,202]中
pm.test("Successful POST request", function () { pm.expect(pm.response.code).to.be.oneOf([201,202]); });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM