python 搭建接口自动化框架

创建项目:

调试接口函数

根据接口文档,在demo中编写对应接口函数(便于调试函数用的)

import requests
import config
import pprint

url = '{}/api/mgr/sq_mgr/'.format(config.HOST)
param = {"action":"list_course","pagenum":1,"pagesize":20}
r = requests.get(url,params=param)
pprint.pprint(r.json())

配置全局变量

在config.py中配置全局变量

HOST = 'http://10.161.54.84'
formheader = {"Content-Type":"application/x-www-form-urlencoded"}
jsonheader = {"Content-Type":"application/json"}
useranme = 'auto'
password = 'sdfsdfsdf'

lib包下定义函数

包含登录,课程新增/列出/删除,requests请求函数,xls表格处理函数

执行用例

扫描二维码关注公众号,回复: 11145778 查看本文章

在doReport.py中编写执行用例

from lib import excelmanageLib
from lib import sendRequstLib
if __name__ == '__main__':
oldpath = 'E:\\apiautotest\data\教管系统-测试用例V1.2.xls'
newpath = 'E:\\apiautotest\\report\教管系统-测试用例执行结果V1.2.xls'
xls = excelmanageLib.excel()
totallist = xls.readExcel(oldpath,0)
xls.getNewexcel(oldpath, newpath)
resultlist = []
for smalllist in totallist:
result = sendRequstLib.RequstsTest(smalllist)
resultlist.append(result)
xls.writeResult(newpath, 0, resultlist)

猜你喜欢

转载自www.cnblogs.com/like1824/p/12796538.html