接口測試工具 Postman

目錄

 

1.界面介紹

2.變量

3.Tests

4.Pre-request Scrip


1.界面介紹

界面介紹

2.變量

變量的訪問:{{variable_key}}

變量的配置:

變量配置

 

3.Tests

示例:

#訪問環境變量 variable_key 
pm.environment.get("variable_key");

#設置環境變量 variable_key = variable_value
pm.environment.set("variable_key", "variable_value");

#斷言響應狀態碼 is 200
pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

#反序列化JSON,提取KeyValue並斷言 == 100
pm.test("Your test name", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData["KeyValue"]).to.eql(100);
});

#斷言相應內容 包含 string_you_want_to_search
pm.test("Body matches string", function () {
    pm.expect(pm.response.text()).to.include("string_you_want_to_search");
});

#斷言響應時間 < 200ms
pm.test("Response time is less than 200ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(200);
});

4.Pre-request Scrip

發送請求前執行的JS腳本,一般用於構建參數,例如請求中加密參數的構建

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章