您的位置:首页 > 理论基础 > 计算机网络

用python做http协议的api自动化测试三

2017-05-07 17:07 567 查看
用例拿出来了,request也自己封装了下,接下来就是把这两个关联起来就行了。

from processParames import processjson
from dotest import dorequest
from comment import check,gettoken
from report.creatreport import CreateReportModel
import setting
class RunCase:

def __init__(self):
"""
初始化....
Paramet,host:域名
"""
self.summerysheetname = r'测试总况'
self.detailssheetname = r'测试详情'
self.check = check.Check()
self.login = gettoken.GetToken().login()
self.writejson = processjson.ProcessJson()
self.createreportmodel = CreateReportModel()
self.num =  {
'test_success':0,
'test_failed':0,
'test_sum': 0,
}
self.data = {'info':[]}

def create_data(self,*args):

nowdata = {'caseid': args[0],'casename': args[1],'token': args[2],'url': args[3]+args[4],'parames': args[5],
'ext': args[6],'act': args[7],'resoult': args[8]}
self.data['info'].append(nowdata)

def runcase(self,length,function):
"""
遍历执行测试用例接口
Params,name:excel sheet名,即域名关键字
"""

token = self.login
request = dorequest.HttpClent(token)

try:
for i in range(length):
caseid,casename,host,api,method,parame,checkdata,ResponseSaveType = function(i)
response = request.runRespuest(host, api, parame,method)
if isinstance(response,str):
self.num['test_failed'] += 1
self.num['test_sum'] += 1
self.create_data(caseid,casename,token,host,api,parame,parame,response,'false')
else:
resoult = self.check.runchek(response,checkdata)
if resoult.lower() == 'pass':
self.num['test_success'] += 1
self.num['test_sum'] += 1
else:
self.num['test_failed'] += 1
self.num['test_sum'] += 1
self.writejson.writeJson(response,ResponseSaveType)
self.create_data(caseid,casename,token,host,api,parame,checkdata,response.text,resoult)
except Exception as e:
print("run运行错误",e)

这个也把结果信息记录了下来,测试报告就自己搞搞就好了。
很简单,也很好用的API自动化测试的一个小框架就搭建好了。
我是小公司的职员,这个够我用了,大公司的自动化不知道怎么做的,我也很向往想见识见识
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: