首页 > 编程语言 > 详细

python+selenium生成测试报告+邮件发送

时间:2019-11-19 17:44:19      阅读:108      评论:0      收藏:0      [点我收藏+]

载入HTMLTestRunner

# 获取当前时间
now = time.strftime("%Y-%m-%M-%H_%M_%S", time.localtime(time.time()))
# 保存生成报告的路径
report_path= "D:\\Users\\wqa\\PycharmProjects\\notification\\report\\"+now+ u"客服系统UI测试报告" +"result.html"
fp = open(report_path,"wb")
runner =HTMLTestRunner.HTMLTestRunner(stream=fp,title=u客服系统UI测试报告,description=u用例执行情况:)
#执行测试用例
runner.run(suite)
fp.close()
print(u测试报告生成地址: + report_path)
time.sleep(5)
#发邮件
send_email(report_path)

发送email代码

def send_email(test_report):
    with open(test_report, r, encoding=utf-8) as f:
     mail_body = f.read()
    f.close()
    mail_host = "smtp.163.com"  # 设置服务器
    mail_user = "3333@163.com"  # 用户名
    mail_pass = "222"  # 口令
    sender = 3333@163.com
    receivers = [3333@qq.com]  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
    message = MIMEText(mail_body, html, utf-8)
    #message = MIMEText(‘Python 邮件发送测试...‘, ‘plain‘, ‘utf-8‘)
    message[From] = 333@163.com
    message[To] = 333@qq.com
    subject = UI自动化测试报告
    message[Subject] = Header(subject, utf-8)
    try:
        smtpObj = smtplib.SMTP_SSL(mail_host, 465)  # 启用SSL发信, 端口一般是465
        smtpObj.login(mail_user, mail_pass)  # 登录验证
        smtpObj.sendmail(sender, receivers, message.as_string())  # 发送
        print("mail has been send successfully.")
    except smtplib.SMTPException as e:
        print(发送邮件异常)

 

python+selenium生成测试报告+邮件发送

原文:https://www.cnblogs.com/seven7777/p/11890628.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!