def start(): starttime = datetime.datetime.now() mtime = datetime.datetime.now().strftime("%Y%m%d") basdir = os.path.abspath(os.path.dirname(__file__)) path = os.path.join(os.path.join(os.getcwd(), 'test_case_data'), 'case.xlsx') listid, listkey, listconeent, listurl, listmethod, listqiwang, listname = datacel( path) listrelust, list_fail, list_pass, list_json, list_weizhi, listone = testinterface( ) filepath = os.path.join(os.path.join(basdir, 'test_Report'), '%s-result.xls' % mtime) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) save_result(starttime, len(listrelust), ((list_pass)), list_fail) create(filename=filepath, list_fail=list_fail, list_pass=list_pass, list_json=list_json, listurls=listurl, listkeys=listkey, listconeents=listconeent, listfangshis=listmethod, listqiwangs=listqiwang, listids=listid, listrelust=listrelust, listnames=listname)
def stast(): starttime = datetime.datetime.now() day = time.strftime("%Y%m%d%H%M", time.localtime(time.time())) basdir = os.path.abspath(os.path.dirname(__file__)) listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel( ) listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi = testinterface( ) filepath = os.path.join(basdir + '\\test_Report\\%s-result.html' % day) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) save_result(starttime, len(listrelust), ((list_pass)), list_fail) endtime = datetime.datetime.now() createHtml(titles='接口测试报告', filepath=filepath, starttime=starttime, endtime=endtime, passge=list_pass, fail=list_fail, id=listid, name=listname, key=listkey, coneent=listconeent, url=listurl, meth=listfangshi, yuqi=listqiwang, json=list_json, relusts=listrelust, weizhi=list_weizhi, exceptions=list_exption)
def start_dubbo_case(): starttime = datetime.datetime.now() day = time.strftime("%Y%m%d%H%M", time.localtime(time.time())) basdir = os.path.abspath(os.path.dirname(__file__)) path = os.getcwd() + '\\test_case_data\\dubbocase.xlsx' listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel( path) listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi = testdubbointerface( ) filepath = os.path.join(basdir + '\\test_Report\\%s-result.html' % day) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) endtime = datetime.datetime.now() createHtml(titles='dubbo接口自动化测试报告', filepath=filepath, starttime=starttime, endtime=endtime, passge=list_pass, fail=list_fail, id=listid, name=listname, key=listkey, coneent=listconeent, url=listurl, meth=listfangshi, yuqi=listqiwang, json=list_json, relusts=listrelust, weizhi=list_weizhi, exceptions=list_exption) contec = 'dubbo接口自动化测试完成,测试通过:%s,测试失败:%s,异常:%s,未知错误:%s,详情见:%s' % ( list_pass, list_fail, list_exption, list_weizhi, filepath) send_ding(content=contec)
def start_excel_report_http(): m = datetime.datetime.now().strftime("%Y%m%d") basdir = os.path.abspath(os.path.dirname(__file__)) path = os.getcwd() + '\\test_case_data\\case.xlsx' listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel( path) listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi = testinterface( ) filepath = os.path.join(basdir + '\\test_Report\\%s-result.xls' % m) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) create(filename=filepath, list_fail=list_fail, list_pass=list_pass, list_json=list_json, listurls=listurl, listkeys=listkey, listconeents=listconeent, listfangshis=listfangshi, listqiwangs=listqiwang, listids=listid, listrelust=listrelust, listnames=listname) contec = 'dubbo接口自动化测试完成,测试通过:%s,测试失败:%s,异常:%s,未知错误:%s,详情见:%s' % ( list_pass, list_fail, list_exption, list_weizhi, filepath) send_ding(content=contec)
def start_interface_html_http(): starttime = datetime.datetime.now() day = time.strftime("%Y%m%d%H%M", time.localtime(time.time())) basdir = os.path.abspath(os.path.dirname(__file__)) path = os.path.join(os.path.join(os.getcwd(), 'test_case_data'), 'case.xlsx') listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel( path) listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi = testinterface( ) filepath = os.path.join(os.path.join(basdir, 'test_Report'), '%s-result.html' % day) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) endtime = datetime.datetime.now() createHtml(titles=u'http接口自动化测试报告', filepath=filepath, starttime=starttime, endtime=endtime, passge=list_pass, fail=list_fail, id=listid, name=listname, key=listkey, coneent=listconeent, url=listurl, meth=listfangshi, yuqi=listqiwang, json=list_json, relusts=listrelust, weizhi=list_weizhi, exceptions=list_exption)
def start(): starttime=datetime.datetime.now() m=datetime.datetime.now().strftime("%Y%m%d") basdir = os.path.abspath(os.path.dirname(__file__)) listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname=datacel() listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi =testinterface() filepath = os.path.join(basdir + '\\test_Report\\%s-result.xls'%m) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) save_result(starttime, len(listrelust), ((list_pass)), list_fail) create(filename=filepath,list_fail=list_fail, list_pass=list_pass, list_json=list_json, listurls=listurl, listkeys=listkey,listconeents=listconeent, listfangshis=listfangshi, listqiwangs=listqiwang, listids=listid, listrelust=listrelust, listnames=listname)
def start_interface_html_http(): starttime = datetime.datetime.now() day = time.strftime("%Y%m%d%H%M", time.localtime(time.time())) basdir = os.path.abspath(os.path.dirname(__file__)) path = os.getcwd() + '\\test_case_data\\case.xlsx' list_id, list_dec, list_param, list_url, list_method, list_expect, list_name = datacel( path) list_relust, list_fail, list_pass, list_json, list_exption, list_weizhi = testinterface( ) # 创建测试报告html文档 filepath = os.path.join(basdir + '\\test_Report\\%s-result.html' % day) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) endtime = datetime.datetime.now() createHtml(titles=u'http接口自动化测试报告', filepath=filepath, starttime=starttime, endtime=endtime, passge=list_pass, fail=list_fail, id=list_id, name=list_name, key=list_dec, coneent=list_param, url=list_url, meth=list_method, yuqi=list_expect, json=list_json, relusts=list_relust, weizhi=list_weizhi, exceptions=list_exption) contec = u'http接口自动化测试完成,测试通过:%s,测试失败:%s,异常:%s,未知错误:%s' % ( list_pass, list_fail, list_exption, list_weizhi) # 发送测试报告 email = Email() email.sendmail(content=contec, filepath=filepath)
def start_excel_report_http(): # m = datetime.datetime.now().strftime("%Y%m%d%H%M%S") m = datetime.datetime.now().strftime("%Y%m%d") basdir = os.path.abspath(os.path.dirname(__file__)) path = os.getcwd() + '\\test_case_data\\case.xlsx' listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel(path) listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi = testinterface() filepath = os.path.join(basdir + '\\test_Report\\%s-result-us.xls' % m) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) create(filename=filepath, list_fail=list_fail, list_pass=list_pass, list_json=list_json, listurls=listurl, listkeys=listkey, listconeents=listconeent, listfangshis=listfangshi, listqiwangs=listqiwang, listids=listid, listrelust=listrelust, listnames=listname) # 邮箱配置 sender = '*****@*****.**' psw = 'lovejt333' # 收件人多个时,中间用逗号隔开,如'[email protected],[email protected]' receiver = '*****@*****.**', '*****@*****.**', '*****@*****.**' # receiver_mail = {'mail': '[email protected], [email protected], [email protected]'} smtp_server = 'smtp.163.com' send_mail(sender, psw, receiver, smtp_server, filepath)
# -*- coding: utf-8 -*- # @Time : 2017/6/4 20:15 # @Author : Three # @File : test_case.py from Interface.testFengzhuang import TestApi from Public.get_excel import datacel from Public.tsest_log import log_re listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname=datacel() from Public.panduan import assert_in title='测试日志' log_can=log_re(title) def testinterface(): list_pass = 0 list_fail = 0 list_json = [] listrelust=[] for i in range(len(listurl)): api=TestApi(url=listurl[i],key=listkey[i],connent=listconeent[i],fangshi=listfangshi[i]) apicode=api.getcode() apijson=api.getJson() log_can.info_log('inputdata> 参数:%s, url:%s ,返回:%s,预期:%s'%(listconeent[i],listurl[i],apijson,listqiwang[i])) assert_re=assert_in(asserqiwang=listqiwang[i],fanhuijson=apijson) if assert_re=='pass': list_json.append(apijson) listrelust.append('pass') list_pass += 1 else: list_fail+=1
""" @author: lileilei @file: dubbocase.py @time: 2018/3/29 12:47 """ from Interface.dubbo_feng import DubboInterface from Public.log import LOG, logger from Public.panduan import assert_in from Public.get_excel import datacel import os path = os.getcwd() + '\\test_case_data\\dubbocase.xlsx' listid, listurl, listinterface, listmeth, listfobject, listparam, listassert = datacel( path) @logger('dubbo接口测试') def testdubbointerface(): list_pass = 0 list_fail = 0 list_json = [] listrelust = [] list_weizhi = 0 list_exption = 0 for i in range(len(listid)): dubboapi = DubboInterface(url=listurl, interface=listinterface[i], method=listmeth[i], param=listfobject[i], **(eval(listparam[i]))) dubboapireslu = dubboapi.getresult()
# -*- coding: utf-8 -*- from Interface.testFengzhuang import TestApi from Public.get_excel import datacel from Public.log import LOG, logger from Public.panduan import assert_in from Public.write import write_to_excel import os import json import datetime import config.config as cf path = cf.CASE_PATH """从Excel单元格取出来后的类型是string""" listid, listname, listisheader, listheader, listdata, listurl, listfangshi, listqiwang = datacel( path) # print(listid, listname, listisheader, listheader, listdata, listurl, listfangshi, listqiwang) @logger('测试') def testinterface(): list_pass = 0 list_fail = 0 list_json = [] listrelust = [] list_weizhi = 0 list_exption = 0 error_num = 0 for i in range(len(listurl)): while error_num <= cf.Case_Fail_Try_Num + 1: """需要将listdata转换成dict在传参""" start_time = datetime.datetime.now()
test_dic = { 'a': '1', 'b': '2', 'c': { 'd': [{ 'e': [{ 'f': [{ 'v': [{ 'g': '6' }, [{ 'g': '7' }, [{ 'g': 8 }]]] }, 'm'] }] }, 'h', { 'g': [10, 12] }] } } # print(get_target_value('a', test_dic, [])) listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel( r"E:\接口测试\jiekou-python3-master\test_case_data\case.xlsx") key = listqiwang[0].split(",", 1)[0] # values = listqiwang[0].split("=")[1] print(key, type(key)) tt = os.getcwd() + '\\saas_sp_1.1.14.yaml' print(tt, type(tt))
class requ(): def get(url, param): # get消息 try: r = requests.get(url, param) r.encoding = 'UTF-8' json_response = json.loads(r.text) return {'code': '200', 'result': json_response} except Exception as e: LOG.info('get请求出错,出错原因:%s' % e) return {'code': '1', 'result': 'get请求出错,出错原因:%s' % e} def post(url, param): # post消息 data = json.dumps(param) try: r = requests.post(url, data) json_response = json.loads(r.text) return {'code': '200', 'result': json_response} except Exception as e: LOG.info('post请求出错,出错原因:%s' % e) return {'code': '1', 'result': 'post请求出错,出错原因:%s' % e} if __name__ == '__main__': list_id, list_name, list_is_header, list_header, list_data, list_url, list_method, list_expect = datacel( cf.CASE_PATH) workbook = xlrd.open_workbook(cf.CASE_PATH) sheet = workbook.sheets()[0] for i in range(len(list_url)): result = requ.post(cf.HOST + list_url[i], json.loads(list_data[i])) LOG.info(result)
def start_interface_html_http(): starttime = datetime.datetime.now() day = time.strftime("%Y%m%d%H%M", time.localtime(time.time())) basdir = os.path.abspath(os.path.dirname(__file__)) path = cf.CASE_PATH listid, listname, listisheader, listheader, listdata, listurl, listfangshi, listqiwang = datacel( path) listrelust, list_fail, list_pass, list_json, list_exption, list_weizhi = testinterface( ) filepath = os.path.join(basdir + '\\test_Report\\%s-result.html' % day) if os.path.exists(filepath) is False: os.system(r'touch %s' % filepath) endtime = datetime.datetime.now() createHtml(titles=u'http接口自动化测试报告', filepath=filepath, starttime=starttime, endtime=endtime, passge=list_pass, fail=list_fail, id=listid, name=listname, is_header=listisheader, header=listheader, url=listurl, meth=listfangshi, yuqi=listqiwang, json=list_json, relusts=listrelust, weizhi=list_weizhi, exceptions=list_exption) contec = u'http接口自动化测试完成,测试通过:%s,测试失败:%s,异常:%s,未知错误:%s,详情见:%s' % ( list_pass, list_fail, list_exption, list_weizhi, filepath) send_demo(contec)
# -*- coding: utf-8 -*- # @Time : 2017/6/4 20:15 # @Author : lileilei # @File : case.py from Interface.testFengzhuang import TestApi from Public.get_excel import datacel from Public.log import LOG, logger import os from config.config_T import Config_Try_Num, TestPlanUrl path = os.getcwd() + '/test_case_data/case.xlsx' listid, listtoken, listconeent, listurl, listfangshi, listqiwang, listname, listbingxing = datacel( path) from Public.panduan import assert_in global list_pass global list_fail global list_json global listrelust global list_elapsed global list_weizhi global list_exption global error_num @logger('测试') def testinterface(): list_pass = 0 list_fail = 0 list_json = [] listrelust = []