def run_case(all_case,result_path=setting.TEST_REPORT): """执行所有的测试用例""" # 初始化接口测试数据 # test_data.init_data() now = time.strftime("%Y-%m-%d %H_%M_%S") filename = result_path + '/' + now + 'result.html' fp = open(filename,'wb') runner = HTMLTestRunner(stream=fp,title='测试用系统接口自动化测试报告', description='环境:windows 7 浏览器:chrome', tester='zhuy') runner.run(all_case) fp.close() report = new_report(setting.TEST_REPORT) #调用模块生成最新的报告 send_mail(report) #调用发送邮件模块
def test_api(self): path = 'D:\Work\Python\AutoTest\Report\测试报告20201218_170609.xlsx' testData = ReadReport(path).read_data() re = send_mail(testData) # re = gettoken() # re = "access_token=" + re # print("获取到的token:%s" % re) # result = comparison(data['result'], re) # testData = TestCase1().userlist() # print("页面返回信息:%s" % testData) #name = "D:\Work\Python\AutoTest\Report\测试报告20201215_104132.xlsx" #redict = dict(zip(["name", "method", "url", "result", "Response"], # ["这是条测试数据","post","www.baidu.com", "测试通过", "response"])) #re = writebook(name, redict) print("re返回:%s")
for i in range(len(allcase)): case = allcase[i] print("第 {0} 条用例,用例名称: {1}".format(i+1,case['name'])) # 发送请求 print("****RUN****") s = requests.session() re = SendRequests().sendRequests(s, case) # 比对执行结果 bl = comparison(case, re) # print ("执行结果123 :%s" %result) print("预期结果 --> {0}".format(case['result'])) if bl: redict = dict(zip(["name", "method", "url", "result", "Response"], [case['name'], case['method'], case['url'], "测试通过", re.content.decode("utf-8")])) reportbl = writebook(bookname, redict) print("测试报告: %s" % reportbl) else: redict = dict(zip(["name", "method", "url", "result", "Response"], [case['name'], case['method'], case['url'], "测试通过", re.content.decode("utf-8")])) reportbl = writebook(bookname, redict) print("测试报告: %s" % reportbl) MailData = ReadReport(name).read_data() #读取执行结果 send_mail(MailData) #发送邮件 if __name__=='__main__': run_case(testData,bookname)