from HTMLTestRunner import HTMLTestRunner
from email.mime.text import MIMEText
from email.header import Header
import smtplib
import unittest
import time
import os
from htmltestrunner import Baidu
def send_mail(file_new):
f = open(file_new, 'rb')
mail_body = f.read()
f.close()
msg = MIMEText(mail_body, 'html', 'utf-8')
msg['Subject'] = Header("百度搜索测试报告", 'utf-8')
smtp = smtplib.SMTP()
smtp.connect("smtp.163.com")
smtp.login("XXXXXXX@163.com", "XXXXXXXX")
smtp.sendmail("XXXXXXXX@163.com", "XXXXXXXX@qq.com", msg.as_string())
smtp.quit()
print('email has send out')
# 查找测试报告目录,找到最新生成的测试报告文件
def new_report(testreport):
# 重新按时间对目录下的文件进行排序
list = os.listdir(testreport)
list.sort(key=lambda fn: os.path.getmtime(testreport + "\\" + fn))
print(('最新文件为:' + list[-1]))
file_new = os.path.join(testreport, list[-1])
print(file_new)
return file_new
if __name__ == '__main__':
test_report = 'F:\\selenium report'
testunit = unittest.TestSuite()
testunit.addTest(Baidu("test_baidu_search"))
now = time.strftime("%Y-%m-%d %H_%M_%S")
filename = test_report + '\\ ' + now + 'result.html'
fp = open(filename, 'wb')
runner = HTMLTestRunner(stream=fp, title='百度搜索测试报告', description='用例执行情况')
runner.run(testunit)
fp.close()
new_report = new_report(test_report)
send_mail(new_report)
python selenium 笔记六-发送最新邮件
最新推荐文章于 2023-03-26 17:23:11 发布