【postman】批量測試接口


主要利用了python的requests方法,可能沒有真正的利用到postman提供的方法,還需要進一步學習。

代碼:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import requests
import json

url = '填你的url'
body = {
填相應的請求體
}
headers = {相應內容填寫}


response = requests.post(url, data=json.dumps(body), headers=headers)

執行這個文件就可以利用組件跑postman
我的批量操作是:
建立了一個xls文件把需要請求的相應數據都放進去
import xlrd
import requests
import json

url = '填你的url'
body = {
填相應的請求體
}
headers = {相應內容填寫}
ex = xlrd.open_workbook(filename=r'測試數據.xls')  # 我的測試數據存的都是文本
sheetbook = ex.sheet_by_index(0)
text = [x for x in sheetbook.col_values(0)]

for i in text:
body['text'] = i # 由於每次執行postman,我只需要修改text,所以根據需要進行調整即可

response = requests.post(url, data=json.dumps(body), headers=headers)
list_test.append(response.text)

utils.write_json_to_file(r'D:/1月任務/批量測試/post_0120.json', list_test) # 寫到json里


雖然實現了批量測試,但是實質上還是相當於一次次去postman請求,還需要學習。ヾ(◍°∇°◍)ノ゙


免責聲明!

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



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