提交 29e16b1a 编写于 作者: Z zhenhua.song

add mail model

上级 ce88d19c
......@@ -52,6 +52,5 @@
----------------------------------------------------------------------------
实际报告如图,分别展现了一个执行失败Case的报错信息+截图,一个执行通过Case的运行日志。
readme_report.png
![readme_report.png](https://github.com/songzhenhua/selenium_ui_auto/blob/master/readme_report.png)
......@@ -22,8 +22,8 @@ def init():
_global_dict['download_path'] = "{}\\file\\download\\".format(root_dir)
# 上传文件夹
_global_dict['upload_path'] = "{}\\file\\upload\\".format(root_dir)
# 存放日志路径
_global_dict['log_path'] = "{}\\report\\".format(root_dir)
# 存放报告路径
_global_dict['report_path'] = "{}\\report\\".format(root_dir)
# 保存driver
_global_dict['driver'] = None
......
无法预览此类型文件
此差异已折叠。
......@@ -9,12 +9,13 @@ import config.config as cf
from util.log import Logger
import argparse
from selenium import webdriver
from util.mail import send_mail
def get_args():
"""命令行参数解析"""
parser = argparse.ArgumentParser(description=u'可选择参数:')
parser.add_argument('-e', '--environment', choices=['preview', 'product'], help=u'测试环境preview,线上环境product')
parser.add_argument('-e', '--environment', choices=['preview', 'product'], default='preview', help=u'测试环境preview,线上环境product')
args = parser.parse_args()
if args.environment in ('pre', 'preview'):
cf.set_value('environment', 'preview')
......@@ -51,4 +52,7 @@ if __name__ == '__main__':
log = Logger('szh') # 初始化log配置
set_driver() # 初始化driver
main() # 运行pytest测试集
cf.get_value('driver').quit() # 关闭selenium driver
\ No newline at end of file
cf.get_value('driver').quit() # 关闭selenium driver
# 先将util.mail文件send_mail()中的用户名、密码填写正确,再启用发送邮件功能!!!
# send_mail(['22459496@qq.com']) # 将报告发送至邮箱
# coding=utf-8
# @Time : 2020/1/25 10:49
# @Author: zhenhua.song
# @File : mail.py
# @Description: 发送邮件
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
import config.config as cf
def send_mail(sendto):
"""
发送邮件
:param sendto:收件人列表,如['22459496@qq.com']
"""
mail_host = 'smtp.sohu.com' # 邮箱服务器地址
username = 'test@sohu.com' # 邮箱用户名
password = 'test' # 邮箱密码
receivers = sendto # 收件人
# 创建一个带附件的实例
message = MIMEMultipart()
message['From'] = Header(u'UI自动化', 'utf-8')
message['subject'] = Header(u'UI自动化测试结果', 'utf-8') # 邮件标题
message.attach(MIMEText(u'测试结果详见附件', 'plain', 'utf-8'))# 邮件正文
# 构造附件
report_root = cf.get_value('report_path') # 获取报告路径
report_file = 'report.html' # 报告文件名称
att1 = MIMEText(open(report_root + report_file, 'rb').read(), 'base64', 'utf-8')
att1["Content-Type"] = 'application/octet-stream'
att1["Content-Disposition"] = 'attachment; filename={}'.format(report_file)
message.attach(att1)
try:
smtp = smtplib.SMTP()
smtp.connect(mail_host, 25) # 25为 SMTP 端口号
smtp.login(username, password)
smtp.sendmail(username, receivers, message.as_string())
print u'邮件发送成功'
except Exception, e:
print u'邮件发送失败'
raise e
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册