Beispiel #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
Beispiel #2
0
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]))
    tr = tr.replace('状态', str(s[3]))
    alltrs += tr

html = html.replace('mailbody', alltrs)

mail.send(html)
#coding:utf8
from lxml import etree
from common.mail import Mail

mail = Mail()

f = open("D:\\1.html", "r", encoding="utf8")  #读取文件
f = f.read()  #把文件内容转化为字符串
html = etree.HTML(f)  #把字符串转化为可处理的格式

# 读取成功率(完全符合xpath语法)
result2 = html.xpath("//*[@class='details']/tr[2]/td[3]")
if result2[0].text == "100.00%":
    print("pass")
else:
    mail.mail_info['filepaths'] = ["D:"]
    mail.mail_info['filenames'] = ["D:\\1.html"]
    mail.send()
Beispiel #4
0
    mysql = Mysql()
    mysql.init_mysql(
        'C:\\Users\\leez\\Documents\\Navicat\\MySQL\\servers\\112\\test_project\\userinfo.sql'
    )

    mail = Mail()
    mail.mail_info['mail_subject'] = r['title'] + '_' + ctime
    mail.mail_info['filepaths'] = [result + ctime + '.xls']
    mail.mail_info['filenames'] = ['result-' + name + '用例' + ctime + '.xls']
    config.config['mail_html'] = config.config['mail_html'].replace(
        'title', r['title'])
    if r['status'] == 'Fail':
        config.config['mail_html'] = config.config['mail_html'].replace(
            'color: #00d800;">status', 'color: #FF0000;">status')
        config.config['mail_html'] = config.config['mail_html'].replace(
            'status', r['status'])
    else:
        config.config['mail_html'] = config.config['mail_html'].replace(
            'status', r['status'])
    config.config['mail_html'] = config.config['mail_html'].replace(
        'runtype', r['runtype'])
    config.config['mail_html'] = config.config['mail_html'].replace(
        'passrate', r['passrate'])
    config.config['mail_html'] = config.config['mail_html'].replace(
        'starttime', r['starttime'])
    config.config['mail_html'] = config.config['mail_html'].replace(
        'casecount', r['casecount'])
    config.config['mail_html'] = config.config['mail_html'].replace(
        'endtime', r['endtime'])
    mail.send(config.config['mail_html'])
Beispiel #5
0
    #         else:
    #             logger.error('非法用例路径')

    config.get_config(path + '/lib/conf/conf.txt')
    # logger.info(config.config)
    # 跑测试用例前将数据库还原
    # mysql = Mysql()
    # mysql.init_mysql(path + '/lib/conf/userinfo.sql')
    runCases()
    res = Res()
    r = res.get_res(resultpath)
    text = config.config['mailtext']
    # 根据执行结果的pass与fail对字体颜色进行设置
    if r['status'] == 'Pass':
        text = text.replace('status', r['status'])
    else:
        text = text.replace(
            '<font style="font-weight: bold;font-size: 14px;color: #00d800;">status</font>',
            '<font style="font-weight: bold;font-size: 14px;color: red;">Fail</font>'
        )

    text = text.replace('passrate', r['passrate'] + '%')
    text = text.replace('casecount', r['casecount'])
    text = text.replace('title', r['title'])
    text = text.replace('runtype', r['runtype'])
    text = text.replace('starttime', r['starttime'])
    text = text.replace('endtime', r['endtime'])

    mail = Mail()
    mail.send(text, resultpath)
Beispiel #6
0
    #执行用例
    config.get_config(path + '/lib/conf/conf.txt')
    #还原数据库
    mysql = Mysql()
    mysql.init_mysql(path + '/lib/mysql/userinfo.sql')
    StartTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    runCase()
    EndTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    res = Res()
    r = res.get_res(resultpath)

    #邮件设置
    text = config.config['mailtext']
    if r['status'] == 'PASS':
        text = text.replace('status', r['status'])
    else:
        text = text.replace(
            '<font style="font-weight: bold;font-size: 14px;color: #00d800;">status</font>',
            '<font style="font-weight: bold;font-size: 14px;color: red;">Fail</font>'
        )
    text = text.replace('passrate', r['passrate'])
    text = text.replace('casecount', r['casecount'])
    text = text.replace('runtype', r['runtype'])
    text = text.replace('title', r['title'])
    text = text.replace('starttime', r['StartTime'])
    text = text.replace('endtime', r['EndTime'])
    config.get_config('./lib/conf/conf.txt')
    mail = Mail()
    mail.send(text)
Beispiel #7
0
            except Exception as e:
                logger.exception(e)

    writer.set_sheet(sheetname[0])
    t = str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
    writer.write(1, 4, t)

    writer.save_close()

    res = Res()
    result = res.get_res('./lib/结果-' + casename)

    mail = Mail()
    mail.mail_info['mail_subject'] = result['title']
    mailtext = config.config['mailtxt']
    mailtext = mailtext.replace('title',result['title'])
    mailtext = mailtext.replace('status', result['status'])
    mailtext = mailtext.replace('runtype', result['runtype'])
    mailtext = mailtext.replace('passrate', result['passrate'])
    mailtext = mailtext.replace('starttime', result['starttime'])
    mailtext = mailtext.replace('casecount', result['casecount'])
    mailtext = mailtext.replace('endtime', result['endtime'])
    if result['status'] == 'Fail':
        mailtext = mailtext.replace('#00d800', 'red')

    # 附件的路径,如果有多个就用,分割
    mail.mail_info['filepaths'] = ['./lib/结果-' + casename]
    mail.mail_info['filenames'] = ['结果-' + casename]

    mail.send(mailtext)