Postman介面測驗-基礎教程
- 前言
- 一、下載安裝Postman
- 二、使用步驟
- 1.普通的get請求
- 2. post請求
- 3. 創建變數
- 4. 預處理 + 斷言
- 5. runner測驗+匯入外部檔案引數text/csv
- 6. 生成在線api檔案
- 總結
前言
提示:本文為小白個人研究成果,僅供參考,如有錯誤歡迎指出
本文有大量貼圖,不要看暈了哦~ ~ ~
一、下載安裝Postman
下載地址:https://www.postman.com/downloads/
選擇自己對應的版本,下載后安裝很簡單直接運行就行了

二、使用步驟
1.普通的get請求
- 創建作業空間、集合


- 創建請求
選擇集合 - 右側的三個點 - Add request




2. post請求
具體是什么引數,要根據檔案或實際情況來



3. 創建變數
分為 環境變數、全域變數、集合變數
名字沖突時,優先環境變數 - 集合變數 - 全域變數
集合變數:作用于整個范圍集合(collections中)
環境變數:作用于當前只用的環境中
全域變數:作用于整個postman



變數的使用


4. 預處理 + 斷言



前置處理代碼案例:
var key = pm.environment.get("param");
console.log("環境變數是:" + key)
key = pm.globals.get("param");
console.log("全域變數是:" + key)
pm.globals.set("quanju-param", "test");
pm.collectionVariables.set("jihe-param", "tests");
pm.variables.set("value", "postman學習");
var value = pm.variables.get("value");
console.log(value)
斷言代碼案例:
pm.test("Code is 200 - 狀態碼是否200", function () {
pm.response.to.have.status(200);
});
pm.test("Contains string - 回傳結果是否包含某個字串", function () {
pm.expect(pm.response.text()).to.include("登陸成功");
});
pm.test("JSON value check - 校驗json的值是否匹配", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.data.city).to.eql("中國");
});
pm.test("is equal to string - 校驗回傳結果是否全等于某欄位", function () {
pm.response.to.have.body({
"msg": "恭喜你 登陸成功",
"code": 0,
"data": {
"city": "中國",
"identity": "學員",
"sex": "女",
"name": "anna小姐姐",
"age": 20
}
});
});
pm.test("Content-Type header check - 校驗請求頭中是否包含某個值", function () {
pm.response.to.have.header("Content-Type");
});
pm.test("time is less than 200ms - 回應時間是否超過某個值", function () {
pm.expect(pm.response.responseTime).to.be.below(10);
});
pm.test("Successful POST request - 是否包含指定狀態碼", function () {
pm.expect(pm.response.code).to.be.oneOf([200, 201, 202]);
});
pm.test("code name has string - 回應狀態碼是否包含某個字串", function () {
pm.response.to.have.status("OK");
});
5. runner測驗+匯入外部檔案引數text/csv
檔案格式: 兩種 txt 和 csv , 注意編碼一定要是utf-8!!!


runner集合測驗 (不同postman版本位置不一樣,需要花點心思找一下)



點擊Run xx 運行


如果切換了簡單視圖的話,是這個樣子的

6. 生成在線api檔案
(不同版本位置不一樣哦!!!)
選中集合 - 點擊三個點 - View documentation


填寫對應配置

點擊Edit settings 即可再次編輯,unpublish則取消發布

生成檔案成功

總結
以上就是今天要講的內容,寫的比較急,postman里面同一種操作可以有很多種方式,由于時間問題我就只寫了一種了,
學無止境,共同進步!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/301331.html
標籤:其他
上一篇:2021-09-18
