标签:Web 测试项目 自动化 mail import path password config subject
一、邮件通知
使用第三方邮件发送库yagmail
github地址:https://github.com/kootenpv/yagmail
安装
pip3 install yagmail
demo.py
import yagmail
# password为登陆密码或者授权码,yagmail SSL默认开启
yag = yagmail.SMTP(user='xxxxxx@163.com', password='xxxxxxx', host='smtp.163.com')
to = 'xxxxxx@qq.com'
subject = 'This is obviously the subject'
body = 'This is obviously the body'
html = '<a href="https://pypi.python.org/pypi/sky/">Click me!</a>'
yag.send(to=to, subject=subject, contents=[body,html])
在config目录下添加mail_config.ini配置文件
[163mail]
user=XXXXXX@163.com
password=XXXXXX
host=smtp.163.com
[project_member]
# 测试人员1
ceshi_1=XXXXXX@qq.com
# 测试人员2
ceshi_2=XXXXXX@qq.com
在utils目录下添加mail_utils.py
mail_utils.py
import yagmail
import configparser
import os
mail_config_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/config' + '/mail_config.ini'
mail_config = configparser.ConfigParser()
mail_config.read(mail_config_path)
user = mail_config['163mail']['user']
password = mail_config['163mail']['password']
host = mail_config['163mail']['host']
def send_mail(to, subject, contents, user=user, password=password, host=host):
'''https://github.com/kootenpv/yagmail'''
yag = yagmail.SMTP(user=user, password=password, host=host)
yag.send(to=to, subject=subject, contents=contents)
更新run_login_case_report.py,调用发送报告
import unittest
import configparser
from module_path import *
from test_case.test_login import TestLoginCase
from utils.se_utils import Driver
from utils.HTMLTestRunnerChart import HTMLTestRunner
from utils.mail_utils import send_mail
if __name__ == '__main__':
###### 执行测试用例 ######
cases = unittest.TestLoader().loadTestsFromTestCase(TestLoginCase)
runner = HTMLTestRunner(
title="自动化测试报告",
description="%s ,%s" % (Driver.get_driver().name, cul_platform),
stream=open(report_path, "wb"),
verbosity=2,
retry=0,
save_last_try=True)
runner.run(cases)
# 所有用例运行完后关闭浏览器
Driver.quit_driver()
###### 邮件发送 ######
config = configparser.ConfigParser()
config.read(mail_config_path)
project_member = config.items('project_member')
subject = 'Web Ui 自动化测试报告'
body = '正文内容'
to = project_member_list = [x[1] for x in project_member]
html = open(report_path, 'r', encoding='utf-8').read()
file = report_path
send_mail(to=to, subject=subject,
contents=[file])
二、钉钉通知
有空再写
标签:Web,测试项目,自动化,mail,import,path,password,config,subject 来源: https://www.cnblogs.com/snailrunning/p/12236330.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。