Exemplo n.º 1
0
def run_case(all_case,result_path=setting.TEST_REPORT):
    """执行所有的测试用例"""
    now = time.strftime("%Y-%m-%d %H_%M_%S")
    filename =  result_path + '/' + now + 'result.html'
    fp = open(filename,'wb')
    runner = HTMLTestRunner(stream=fp,title='抽屉新热榜UI自动化测试报告',
                            description='环境:windows 7 浏览器:chrome',
                            tester='Jason')
    runner.run(all_case)
    fp.close()
    report = new_report(setting.TEST_REPORT) #调用模块生成最新的报告
    send_mail(report) #调用发送邮件模块
Exemplo n.º 2
0
def send_mail(file_new):
    """
    定义发送邮件
    :param file_new:
    :return: 成功:打印发送邮箱成功;失败:返回失败信息
    """
    f = open(file_new, 'rb')
    mail_body = f.read()
    f.close()
    # 发送附件
    con = configparser.ConfigParser()
    con.read(setting.CONFIG_DIR, encoding='utf-8')
    report = new_report(setting.TEST_REPORT)
    sendfile = open(report, 'rb').read()

    # --------- 读取config.ini配置文件 ---------------
    HOST = con.get("user", "HOST_SERVER")
    SENDER = con.get("user", "FROM")
    RECEIVER = con.get("user", "TO")
    USER = con.get("user", "user")
    PWD = con.get("user", "password")
    SUBJECT = con.get("user", "SUBJECT")

    att = MIMEText(sendfile, 'base64', 'utf-8')
    att["Content-Type"] = 'application/octet-stream'
    att.add_header("Content-Disposition",
                   "attachment",
                   filename=("gbk", "", report))

    msg = MIMEMultipart('related')
    msg.attach(att)
    msgtext = MIMEText(mail_body, 'html', 'utf-8')
    msg.attach(msgtext)
    msg['Subject'] = SUBJECT
    msg['from'] = SENDER
    msg['to'] = RECEIVER

    try:
        server = smtplib.SMTP()
        server.connect(HOST)
        server.starttls()
        server.login(USER, PWD)
        server.sendmail(SENDER, RECEIVER, msg.as_string())
        server.quit()
        print("邮件发送成功!")
    except Exception as e:
        print("失败: " + str(e))
Exemplo n.º 3
0
def email(file_new):
    f = open(file_new, 'rb')
    mail_body = f.read()
    f.close()
    #发送附件
    con = configparser.ConfigParser()
    con.read(setting.CONFIG_DIR, encoding='utf-8')
    report = new_report(setting.TEST_REPORT)
    sendfile = open(report, 'rb').read()

    mail_host = "smtp.exmail.qq.com"  # ÉèÖ÷þÎñÆ÷
    mail_user = "******"  # ̞
    mail_pass = "******"  # ¿ÚÁî
    sender = '*****@*****.**'
    receivers = ['*****@*****.**'
                 ]  # ½ÓÊÕÓʼþ£¬¿ÉÉèÖÃΪÄãµÄQQÓÊÏä»òÕßÆäËûÓÊÏä
    subject = "自动化测试报告"

    att = MIMEText(sendfile, 'base64', 'utf-8')
    att["Content-Type"] = 'application/octet-stream'
    att.add_header("Content-Disposition",
                   "attachment",
                   filename=("gbk", "", report))

    msg = MIMEMultipart('related')
    msg.attach(att)
    msgtext = MIMEText(mail_body, 'html', 'utf-8')

    msg.attach(msgtext)
    msg['Subject'] = subject
    msg['from'] = sender
    msg['to'] = receivers

    try:
        # smtpObj = smtplib.SMTP_SSL("smtp.exmail.qq.com", port=465)
        # smtpObj.login(mail_user, mail_pass)
        # smtpObj.sendmail(sender, receivers, msg.as_string())
        server = smtplib.SMTP()
        server.connect("smtp.exmail.qq.com", port=465)
        server.starttls()
        server.login(mail_user, mail_pass)
        server.sendmail(sender, receivers, msg.as_string())
        server.quit()
        print("邮件发送成功!")

    except smtplib.SMTPException:
        print("发送失败")