接口测试框架-使用类封装接口测试脚本(get post)
一 安装requests
cmd中输入 pip install requests
二 安装成功验证
在python下输入import requests,导入成功,则安装成功
三 封装类
import requestsimport jsonclass RunMain: def __init__(self,url,method,data=None): self.res = self.run_main(url,method,data) def send_get(self, url, data): res = requests.get(url=url, data=data).json() return json.dumps(res,indent=2,sort_keys=True) def send_post(self, url, data): res = requests.post(url=url, data=data).json() return json.dumps(res,indent=2,sort_keys=True)#格式化输出 def run_main(self, url, method, data=None): res = None if method == ‘GET‘: res = self.send_get(url, data) else: res = self.send_post(url, data) return resif __name__ == ‘__main__‘: url = ‘http://www.imooc.com/m/web/shizhanapi/loadmorepingjia.html?cart=11‘ data = { ‘cart‘: ‘11‘ } run = RunMain(url,‘GET‘,data) print (run.res)
相关推荐
chichichi0 2020-06-16
knightwatch 2020-07-19
Richardxx 2020-07-26
sunnyhappy0 2020-07-26
Guanjs0 2020-11-09
wmsjlihuan 2020-09-15
shishengsoft 2020-09-15
poplpsure 2020-08-17
CyborgLin 2020-08-15
wcqwcq 2020-07-04
YAruli 2020-06-13
JF0 2020-06-13
84423067 2020-06-12
心丨悦 2020-06-11
zkwgpp 2020-06-04
stoneechogx 2020-06-04
litterfrog 2020-05-30
today0 2020-05-26