示例#1
0
def getCode():
    if request.method == "POST":
        emailAddress = request.form.get("userName")
        code = Code().gen_code()
        session['code'] = code
        mail = Mail()
        msg = mail.send(emailAddress, code)
        return msg
示例#2
0
def send_mail(title):
    try:
        server = Server(SMTP_SERVER, PASSWORD, FROM_ADDR)
        if server.connet():
            mail = Mail(server, TO_ADDRS)
            mail.mail_title = title
            mail.mail_content = '股票提醒消息来了'
            mail.send_mail()
        server.close()
        print('mail send out!')
    except Exception as e:
        print(e)
        print('mail send failed!')
示例#3
0
writer.set_sheet(sheetname[0])
endtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
writer.write(1, 4, endtime)
writer.save_close()

# 结果统计
res = Res()
details = res.get_res('./lib/result-%s.xls' % casename)
r = res.get_groups('./lib/result-%s.xls' % casename)

# 关闭jvm
shutdown()

# 邮件处理
mail = Mail()
htmlmodule = Txt('./conf/' + config.config['mailtxt'])
html = htmlmodule.read()[0]
# 对模块文本进行处理
# 替换总体统计信息
sumlist = ['status', 'passrate', 'starttime', 'endtime']
for s in sumlist:
    html = html.replace(s, details[s])

# 生成HTML的一行内容
alltrs = ''
for s in r:
    tr = '<tr><td width="100" height="28" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">分组信息</td><td width="80" height="28" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">用例总数</td><td width="80" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">通过数</td><td width="80" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">状态</td></tr>'
    tr = tr.replace('分组信息', str(s[0]))
    tr = tr.replace('用例总数', str(s[1]))
    tr = tr.replace('通过数', str(s[2]))
示例#4
0
            '<td height="28" bgcolor="#FFFFFF" align="center" style="border:1px solid #ccc;">status</td>',
            '<td height="28" bgcolor="#FFFFFF" align="center" style="border:1px solid #ccc;color:blue;">Pass</td>'
        )
    elif summary[key] == "Fail":
        html = html.replace(
            '<td height="28" bgcolor="#FFFFFF" align="center" style="border:1px solid #ccc;">status</td>',
            '<td height="28" bgcolor="#FFFFFF" align="center" style="border:1px solid #ccc;color:red;">Fail</td>'
        )
    else:
        html = html.replace(key, summary[key])

# 获取分组显示
tr = '<tr><td width="35" height="28" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">自动化类型</td><td width="70" height="28" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">用例表名</td><td width="100" height="28" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">分组信息</td><td width="50" height="28" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">用例总数</td><td width="50" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">通过数</td><td width="50" align="center" bgcolor="#FFFFFF" style="border:1px solid #ccc;">状态</td></tr>'
trs = ""

for i in range(len(groups)):
    try:
        tmp = tr.replace('自动化类型', str(groups[i][0]))
        tmp = tmp.replace('用例表名', str(groups[i][1]))
        tmp = tmp.replace('分组信息', str(groups[i][2]))
        tmp = tmp.replace('用例总数', str(groups[i][3]))
        tmp = tmp.replace('通过数', str(groups[i][4]))
        tmp = tmp.replace('状态', str(groups[i][5]))
    except Exception as e:
        logger.error(str(e))
    trs += tmp

html = html.replace('mailbody', trs)
mail = Mail([f'./lib/{casename}_result.xlsx'], [f'{casename}_测试报告详情.xlsx'])
mail.send(html)
def run(casename="多线程APP1"):
    # 运行的相对路径

    path = '.'
    # 用例路径
    casepath = ''
    resultpath = ''

    logger.info("开始用例")
    try:
        casepath = sys.argv[1]
    except:
        casepath = ''
    casefile = casename
    # 为空,则使用默认的
    if casepath == '':
        casepath = path + '/data/cases/' + casefile + '.xls'
        resultpath = path + '/outputs/resultcases/chint结果-' + casefile + '.xls'
    else:
        # 如果是绝对路径,就使用绝对路径
        if casepath.find(':') >= 0:
            # 获取用例文件名
            resultpath = path + '/outputs/resultcases/chint结果-' + casepath[
                casepath.rfind('\\') + 1:]
        else:
            logger.error('非法用例路径')

    config.get_config(path + '/conf/conf.properties')
    # logger.info(config.config)
    # mysql = Mysql()
    # mysql.init_mysql(path + '/lib/userinfo.sql')
    logger.info("传递的参数是:%s,%s" % (casepath, resultpath))
    datadriven.getparams(casepath, resultpath)
    # print(datadriven.alllist)

    ### 下面三行代码为BeautifulReport 报告
    # suite = unittest.defaultTestLoader.discover("./utest/", pattern="WebTest.py", top_level_dir=None)
    # # 生成执行用例的对象
    # runner = bf(suite)
    # runner.report(filename='./report/test'+ casefile + '.html', description=datadriven.title)

    ### 下面几行代码为HTMLTestRunner 报告
    suite = unittest.defaultTestLoader.discover("./utest/",
                                                pattern="WebTest.py",
                                                top_level_dir=None)
    # 生成执行用例的对象
    runner = bf(suite)
    runner.report(filename='./outputs/report/test' + casefile + '.html',
                  description=datadriven.title)

    # 记录结束时间,写入结果文件
    endtime = str(
        datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))  # 用例结束时间
    datadriven.writer.set_sheet((datadriven.writer.get_sheets())[0])
    datadriven.writer.write(1, 4, endtime)  # 对结果文件第二行第四列写入开始时间

    # 保存结果文件
    datadriven.writer.save_close()

    # # 得到报告数据
    res = Res()
    r = res.get_res(resultpath)

    # 读取配置文件
    config.get_config('./conf/conf.properties')
    # logger.info(config.config)
    # logger.info(config.config['mail'])
    # 修改邮件数据
    html = config.config['mailtxt']  # 读取报告模板
    html = html.replace('title', r['title'])  # 替换模板中的数据
    html = html.replace('runtype', r['runtype'])
    html = html.replace('passrate', r['passrate'])
    html = html.replace('status', r['status'])
    html = html.replace('casecount', r['casecount'])
    html = html.replace('starttime', r['starttime'])
    html = html.replace('endtime', r['endtime'])

    if r['status'] == 'Fail':
        html = html.replace('#00d800', 'red')

    # 根据结果决定是否发送邮件
    if r['status'] == 'Fail':
        logger.info("开始发送邮件")
        mail = Mail()
    #     mail.send(html)

    logger.info("结束用例")
示例#6
0
    with open(report_path, 'wb') as report:
        runner = HTMLTestRunner(stream=report,
                                title=report_title,
                                description="")
        runner.run(testsuite)
    return report_path


if __name__ == "__main__":
    if testcaseid_list or mixcase_list:
        generate_testcases(testcaseid_list)
        generate_mix_testcase(mixcase_list)
        testsuite = generate_testsuite(testcaseid_list, mixid_list)
        logger.info("【开始执行用例】")
        report_path = run(testsuite)
        logger.info("【结束执行用例】")
        logger.info("")
        flag = int(readconfig.if_send)
        if flag:
            logger.info("【正在发送邮件报告】")
            mail = Mail(readconfig.email_host, readconfig.email_user,
                        readconfig.email_psw)
            content = "自动化测试已结束,请查收测试报告"
            mail.send_mail(readconfig.Receivers, '自动化测试报告', content,
                           report_path)
            logger.info("【邮件报告发送结束】")
            logger.info("")
    else:
        logger.info("缺少用例数据,请指定或者添加相应的用例数据")
        logger.info("")
示例#7
0
import unittest
from common.HTMLTestRunner_cn import HTMLTestRunner
import os
import time
from common.mail import Mail

yag = Mail()
case_path = os.path.join(os.getcwd(), 'case')
report_path = os.path.join(os.getcwd(), 'report')


def all_case():
    '''构造待执行的测试用例'''
    discover = unittest.defaultTestLoader.discover(case_path,
                                                   pattern='test*.py')
    print(discover)
    return discover


if __name__ == '__main__':
    now_time = time.strftime('%Y-%m-%d %H_%M_%S')
    filename = os.path.join(report_path, now_time + 'result.html')
    fp = open(filename, 'wb')
    # 执行测试,输出HTML格式的测试报告
    runner = HTMLTestRunner(stream=fp, title='自动化测试报告', description='用例执行情况:')
    runner.run(all_case())
    fp.close()
    yag.send_mail(filename)  #发送邮件