我的账户
啄木鸟学院

专注软件测试菁英教育

亲爱的游客,欢迎!

已有账号,请

如尚未注册?

Selenium_赵梦冰_20210302

[复制链接]
Loading...学员认证 发表于 2021-3-2 18:39:23 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
from base.HTMLTestRunner import HTMLTestRunner
import unittest,time
class TestRunner:
    def runner(self):
        #实例化测试套件
        suite = unittest.TestSuite()
        #添加测试用例
        suite.addTests(unittest.TestLoader().discover(r'selenium\ranzhi\test',pattern='login_test.py'))
        #创建一个时间戳
        #在文件名加一个时间戳生成新的文件
        timestamp = time.strftime('%Y-%m-%d_%H-%M-%S')
        #创建报告文件
        report = open('selenium\\ranzhi\\report\\report_%s.html'%timestamp,mode='wb')
        # report = open('selenium/ranzhi/report/report_%s.html'%timestamp,mode='wb')  两种都可以
        #创建用例运行器
        test_runner = HTMLTestRunner(stream=report,title='Ranzhi自动化测试报告',description='报告详细内容...')
        #运行报告
        test_runner.run(suite)
        #发送报告
if __name__ == '__main__':
    TestRunner().runner()
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
#设置邮件服务器地址
smtpserver = 'smtp.163.com'
#设置邮件服务器端口号
port = 25
#发件人地址
sender = 'z15129299705@163.com'
#密码或授权码
password = 'NNWAMIKTQZOVNIAJ'
#收件人
receivers = 'z744277252@163.com;15091835804@163.com'
#创建邮件对象
mail = MIMEMultipart()
#初始化发件人
mail['from'] = sender
#添加收件人
mail['to'] = receivers
#添加主题
mail['subject'] = 'Ranzhi自动化测试报告'
#读取附件
path = 'selenium/ranzhi/report/report_2021-03-02_15-23-36.html'
with open(path,'rb')as file:
    report = file.read()
#对附件进行编码
attachment = MIMEText(report,'base64','utf-8')
#设置附件的类型
attachment['Content-Type'] = 'application/octet-stream'
#设置附件的处理方式
attachment['Content-Disposition'] = 'attachment;filename=%s'%path.split('/')[-1]
#添加附件
mail.attach(attachment)
#生成邮件正文
content = '''
<p>Dear Mike,</p>
<p>    这里是<u>Ranzhi</u>项目的测试报告,请您查收!</p>
<p>此致</p>
<p>Tom Cruse</p>
'''
#对邮件正文进行编码
body = MIMEText(content,'html','utf-8')
#添加正文
mail.attach(body)
#创建SMIP对象
smtp = smtplib.SMTP()
#连接服务器
smtp.connect(smtpserver,port)
#登录服务器
smtp.login(sender,password)
#发送邮件
smtp.sendmail(sender,receivers.split(';'),mail.as_string())
# 关闭服务器
smtp.close()
print('邮件发送完毕!')




回复

使用道具 举报

关注0

粉丝0

帖子26

发布主题
大家都在学
课堂讨论
一周热帖排行最近7x24小时热帖
关注我们
专注软件测试菁英教育

客服电话:17792550360

客服时间:9:00-21:00

卓目鸟学苑 - 专注软件测试菁英教育!( 陕ICP备2025058934号-2 )

版权所有 © 西安菁英教育科技有限公司 2023-2026