Пример #1
0
# coding:utf-8
from tkinter import *
from new_api_cases.check_result import CheckResult
from api_test_cases.get_execution_output_json import GetCheckoutDataSet

root = Tk()
w1 = Label(root, text=r'你可以在该页面进行测试用例的新增,编辑,执行等操作')

w1.config(fg='black', font=('隶书', 16, 'bold'), pady=30)  # text的字体颜色,和背景颜色
w1.place(x=210, y=0)

b1 = Button(text='执行API测试用例', command=CheckResult().deal_result)
b2 = Button(text='执行Flow测试用例', command=GetCheckoutDataSet().get_json)
b1.config(font=('隶书', 15, 'bold'), padx=5, pady=5)
b2.config(font=('宋体', 15, 'bold'), padx=5, pady=5)
b1.place(x=250, y=180)
b2.place(x=550, y=180)
root.config(width=1000, height=500)
mainloop()
Пример #2
0
# coding:utf-8
from util.send_mail import mail_for_flow
from api_test_cases.get_execution_output_json import GetCheckoutDataSet
from basic_info.setting import host
import datetime
from basic_info.setting import receivers_list, receivers_test

print('------开始执行用例-------')
start_time = datetime.datetime.now()
print('用例执行环境:', host)
print('开始时间', start_time)
print('------开始执行flow用例------')
# 执行flow用例
obj = GetCheckoutDataSet()
obj.get_json()
print('------开始执行api case------')
# 执行API用例
# deal_request_method()
# # 对比API用例结果
# CheckResult().deal_result()
# 发送邮件
print('用例执行完毕,开始发送邮件')
stop_time = datetime.datetime.now()
print('结束时间:', stop_time)
print('耗时:', stop_time - start_time)
# 发送邮件
# mail_for_flow(host,receivers_list)
Пример #3
0
    for test_case in test_suite:
        # print(test_case)
        testcase.addTest(test_case)
filename = time.strftime("%Y%m%d%H", time.localtime()) + '_report.html'
report_path = 'E:\Reports\\' + filename
# report_path = '/root/gbj/Reports/' + filename  # 192.168.1.87环境Jenkins使用
fp = open(report_path, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='API自动化测试报告', description='覆盖dataset,schema,schedulers,execution等测试场景')
print('开始执行API自动化脚本')
start_time = datetime.datetime.now()
print('start_time:', start_time)
runner.run(testcase)
fp.close()
print('自动化脚本执行结束,开始执行flow用例')
# 执行flow用例
obj = GetCheckoutDataSet()
sink_dataet_json = obj.get_json()
print('开始执行excel 版本api case')
# 执行API用例
deal_request_method()
# 对比API用例结果
CheckResult().deal_result()
# 发送邮件
main3(report_path=report_path)
stop_time = datetime.datetime.now()
print('耗时:', stop_time-start_time)
# threading.Timer(1500, get_headers()).start()
# print('重新发送一次TOKEN')


Пример #4
0
def mail_for_flow(host, receivers):
    # 163邮箱smtp服务器
    host_server = "smtp.163.com"
    # 发件人
    sender_163 = "*****@*****.**"
    # pwd为发件人163邮箱的授权码
    pwd = "OVTVEQJNXXUEKTVV"
    # 发件人的邮箱
    sender_163_mail = "*****@*****.**"
    # 收件人邮箱
    #receivers = receivers_test  # 调试使用
    receivers = receivers_list  # 定时任务使用
    msg = MIMEMultipart()
    # 邮件的正文内容----flow执行结果
    f = load_workbook(abs_dir("flow_dataset_info.xlsx"))
    f_sheet = f.get_sheet_by_name("flow_info")
    rows = f_sheet.max_row
    succeed_flow = []
    failed_flow = []
    flow_id_list = GetCheckoutDataSet().get_flow_id()
    total = len(list(set(flow_id_list)))
    # print('flow总数total:', total)
    detail_msg = ''' '''
    for row in range(2, rows + 1):
        if f_sheet.cell(row=row, column=9).value == "fail":
            detail_msg += f_sheet.cell(row=row, column=10).value + '\n'
            if f_sheet.cell(row=row, column=3).value:
                failed_flow.append(f_sheet.cell(row=row, column=3).value)
            else:
                for i in range(row, 2, -1):
                    if f_sheet.cell(row=i - 1, column=3).value:
                        failed_flow.append(
                            f_sheet.cell(row=i - 1, column=3).value)
                        break
        elif f_sheet.cell(row=row, column=9).value == "pass":
            if f_sheet.cell(row=row, column=3).value:
                succeed_flow.append(f_sheet.cell(row=row, column=3).value)
                # print(succeed_flow)
            else:
                for i in range(row, 2, -1):
                    if f_sheet.cell(row=i - 1, column=3).value:
                        succeed_flow.append(
                            f_sheet.cell(row=i - 1, column=3).value)
                        break
    failed_flow_s = list(set(failed_flow))
    succeed_flow_s = list(set(succeed_flow))
    for disct_id in (disct_ids for disct_ids in failed_flow_s
                     if disct_ids in succeed_flow_s):
        succeed_flow_s.remove(disct_id)

    # 邮件的正文内容
    filename = time.strftime("%Y%m%d%H", time.localtime()) + '_report.html'
    if len(failed_flow_s) != 0:
        mail_content = """各位好:
        flow用例执行信息如下:
        用例执行环境:%s
        本次Flow用例共执行:%d 个
        执行成功: %d 个
        执行失败: %d 个
        失败的flow名称为:
        %s
        失败原因请查看附件《flow_info.xlsx》中的log信息""" % (host, total, len(
            succeed_flow_s), len(failed_flow_s), failed_flow_s)
    else:
        mail_content = """各位好:
        flow用例执行信息如下:
        用例执行环境:%s
        本次Flow用例共执行: %d 个
        成功: %d 个
        任务详情请查看附件《flow_info.xlsx》中的log""" % (host, total, len(succeed_flow_s))
    # print(mail_content)
    # 邮件标题
    mail_title = time.strftime("%Y-%m-%d", time.localtime()) + ' Flow用例自动化执行日报'

    # 添加邮件正文,格式 MIMEText:
    msg.attach(MIMEText(mail_content, "plain", 'utf-8'))

    # 添加附件,就是加上一个MIMEBase,从本地读取一个文件:
    flow_filepath = abs_dir('flow_dataset_info.xlsx')
    with open(flow_filepath, 'rb') as ff:
        # 设置附件的MIME和文件名,这里是html类型:
        flow_mime = MIMEBase('report', 'xlsx', filename='flow_info.xlsx')
        # 加上必要的头信息:
        flow_mime.add_header('Content-Disposition',
                             'attachment',
                             filename='flow_info.xlsx')
        flow_mime.add_header('Content-ID', '<0>')
        flow_mime.add_header('X-Attachment-Id', '0')
        # 把附件的内容读进来:
        flow_mime.set_payload(ff.read())
        # # 用Base64编码:
        encoders.encode_base64(flow_mime)
        # 添加到MIMEMultipart:
        msg.attach(flow_mime)

    # ssl登录
    smtp = SMTP_SSL(host_server)
    # set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式
    smtp.set_debuglevel(0)
    smtp.ehlo(host_server)
    smtp.login(sender_163_mail, pwd)
    msg["Subject"] = Header(mail_title, 'utf-8')
    msg["From"] = sender_163
    msg["To"] = Header("gjb,fq,wzm", 'utf-8')  # 接收者的别名
    smtp.sendmail(sender_163_mail, receivers, msg.as_string())
    print('%s----发送邮件成功' %
          time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    smtp.quit()
Пример #5
0
def main3(report_path):
    # 163邮箱smtp服务器
    host_server = "smtp.163.com"
    # sender_163为发件人的163邮箱
    sender_163 = "*****@*****.**"
    # pwd为163邮箱的授权码
    pwd = "ruifantest2018"
    # 发件人的邮箱
    sender_163_mail = "*****@*****.**"
    # 收件人邮箱
    receivers = [
        '*****@*****.**', '*****@*****.**',
        '*****@*****.**', '*****@*****.**',
        '*****@*****.**'
    ]  # 定时任务使用
    # receivers = ['*****@*****.**']  # 调试使用
    msg = MIMEMultipart()
    # 邮件的正文内容----flow执行结果
    f = load_workbook(abs_dir("flow_dataset_info.xlsx"))
    f_sheet = f.get_sheet_by_name("flow_info")
    cols = f_sheet.max_column
    rows = f_sheet.max_row
    succeed = 0
    succeed_flow = []
    failed = 0
    failed_flow = []
    flow_failed_detail = []
    flow_id_list = GetCheckoutDataSet().file_flowid_count()
    total = len(flow_id_list)
    print('flow总数total:', total)
    detail_msg = ''' '''
    for row in range(2, rows + 1):
        if f_sheet.cell(row=row, column=9).value == "fail":
            detail_msg += f_sheet.cell(row=row, column=10).value + '\n'
            if f_sheet.cell(row=row, column=3).value:
                failed_flow.append(f_sheet.cell(row=row, column=3).value)
            else:
                for i in range(row, 2, -1):
                    if f_sheet.cell(row=i - 1, column=3).value:
                        failed_flow.append(
                            f_sheet.cell(row=i - 1, column=3).value)
                        break
        elif f_sheet.cell(row=row, column=9).value == "pass":
            if f_sheet.cell(row=row, column=3).value:
                succeed_flow.append(f_sheet.cell(row=row, column=3).value)
                # print(succeed_flow)
            else:
                for i in range(row, 2, -1):
                    if f_sheet.cell(row=i - 1, column=3).value:
                        succeed_flow.append(
                            f_sheet.cell(row=i - 1, column=3).value)
                        break
    failed_flow_s = list(set(failed_flow))
    succeed_flow_s = list(set(succeed_flow))
    for disct_id in (disct_ids for disct_ids in failed_flow_s
                     if disct_ids in succeed_flow_s):
        succeed_flow_s.remove(disct_id)
    # 邮件的正文内容----API执行结果
    # 统计api执行结果,加入到邮件正文中,失败的用例name,失败的原因
    api_cases_table = load_workbook(table_dir('api_cases.xlsx'))
    cases_sheet = api_cases_table.get_sheet_by_name('tester')
    sheet_rows = cases_sheet.max_row
    cases_num = sheet_rows - 1
    pass_cases = 0
    failed_cases = 0
    failed_cases_list = []
    for row in range(2, sheet_rows + 1):
        if cases_sheet.cell(row=row, column=14).value == 'pass':
            pass_cases += 1
        elif cases_sheet.cell(row=row, column=14).value == 'fail':
            failed_cases += 1
            # k = cases_sheet.cell(row=row, column=2).value
            # v = cases_sheet.cell(row=row, column=15).value
            # dict = {k: v}
            failed_cases_list.append(
                cases_sheet.cell(row=row, column=15).value)
        else:
            print('请确认第%d行测试用例测试结果' % row)

    # 邮件的正文内容
    filename = time.strftime("%Y%m%d%H", time.localtime()) + '_report.html'
    if len(failed_flow_s) > 0:
        mail_content = '\n各位好:'+'\n' + '\n' + \
                    '一、API的测试用例结果请参考附件<<%s>>' % filename + '\n'\
                    + '-------------------------------------------------------------' + '\n'\
                       + '二、Flow用例共 %d 个\n成功%d个, 失败 %d个\n失败的flow name为 %s\n失败原因为:\n ' % (total, len(succeed_flow_s), len(failed_flow_s), failed_flow_s) + detail_msg + \
                       '-------------------------------------------------------------' + '\n' + \
                       '三、 API测试用例共%d个,\n成功%d个, 失败%d个,失败的case info: \n%s' \
                       % (cases_num, pass_cases, failed_cases, failed_cases_list)
    else:
        mail_content = '\n各位好:' + '\n' + \
                       '一、API的测试用例结果请参考附件<<%s>>' % filename + '\n' \
                   + '--------------------------------------------------------------' + '\n' \
                       + '二、flow用例共 %d 个\n成功%d个, 失败 %d个\n' % (total, len(succeed_flow_s), len(failed_flow_s)) + '\n' \
                       + '--------------------------------------------------------------' + '\n' + \
                       '三、API测试用例共%d个,\n成功%d个, 失败%d个,失败的case info: \n%s' \
                       % (cases_num, pass_cases, failed_cases, failed_cases_list)
    # print(mail_content)
    # 邮件标题
    # mail_title = time.strftime("%Y-%m-%d 自动化日报", time.localtime())
    mail_title = time.strftime("%Y-%m-%d", time.localtime()) + ' API自动化测试日报'
    # 添加邮件正文,格式 MIMEText:
    msg.attach(MIMEText(mail_content, "plain", 'utf-8'))

    # 添加附件,就是加上一个MIMEBase,从本地读取一个文件:
    # 添加API用例集执行报告
    filename = time.strftime("%Y%m%d%H", time.localtime()) + '_report.html'
    with open(report_path, 'rb') as f:
        # 设置附件的MIME和文件名,这里是html类型:
        mime = MIMEBase('report', 'html', filename=filename)
        # 加上必要的头信息:
        mime.add_header('Content-Disposition', 'attachment', filename=filename)
        mime.add_header('Content-ID', '<0>')
        mime.add_header('X-Attachment-Id', '0')
        # 把附件的内容读进来:
        mime.set_payload(f.read())
        # # 用Base64编码:
        encoders.encode_base64(mime)
        # 添加到MIMEMultipart:
        msg.attach(mime)
    # 添加api用例 excel表格
    apicases_filepath = table_dir('api_cases.xlsx')
    with open(apicases_filepath, 'rb') as a:
        # 设置附件的MIME和文件名,这里是html类型:
        mime = MIMEBase('report', 'xlsx', filename='api_cases.xlsx')
        # 加上必要的头信息:
        mime.add_header('Content-Disposition',
                        'attachment',
                        filename='api_casex.xlsx')
        mime.add_header('Content-ID', '<0>')
        mime.add_header('X-Attachment-Id', '0')
        # 把附件的内容读进来:
        mime.set_payload(a.read())
        # # 用Base64编码:
        encoders.encode_base64(mime)
        # 添加到MIMEMultipart:
        msg.attach(mime)

    flow_filepath = abs_dir('flow_dataset_info.xlsx')
    with open(flow_filepath, 'rb') as ff:
        # 设置附件的MIME和文件名,这里是html类型:
        mime = MIMEBase('report', 'xlsx', filename='flow_info.xlsx')
        # 加上必要的头信息:
        mime.add_header('Content-Disposition',
                        'attachment',
                        filename='flow_info.xlsx')
        mime.add_header('Content-ID', '<0>')
        mime.add_header('X-Attachment-Id', '0')
        # 把附件的内容读进来:
        mime.set_payload(ff.read())
        # # 用Base64编码:
        encoders.encode_base64(mime)
        # 添加到MIMEMultipart:
        msg.attach(mime)

    # ssl登录
    smtp = SMTP_SSL(host_server)
    # set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式
    smtp.set_debuglevel(0)
    smtp.ehlo(host_server)
    smtp.login(sender_163, pwd)
    msg["Subject"] = Header(mail_title, 'utf-8')
    msg["From"] = sender_163_mail
    msg["To"] = Header("顾冰洁,王志明,彭媛", 'utf-8')  # 接收者的别名
    smtp.sendmail(sender_163_mail, receivers, msg.as_string())
    print('%s----发送邮件成功' %
          time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    smtp.quit()


# report_path = 'E:\Reports\\2018122813_report.html'
# main3(report_path)
# apicases_filepath = table_dir('api_cases.xlse')
# # # print(apicases_filepath)