zoukankan      html  css  js  c++  java
  • selenium自动发送邮件

    1.我们已经完成了selenium生成测试报告,那我们要做将测试报告发送给相关人员,就可以这样使用

    #coding: utf - 8
    from case.t_single import Sin
    from case.test_baidu import Ceshi
    from case.test_bokeyuan import Bo
    from unittest import TestSuite,TestLoader
    import unittest,time,os
    import HTMLTestRunner
    import smtplib#发送邮件模块
    from email.mime.text import MIMEText #定义邮件neir
    from email.header import Header #定义邮件标题
    from email.mime.multipart import MIMEMultipart

    def run_main():
    suit = unittest.TestSuite()
    suit.addTest(Bo('test_shouye'))
    suit.addTest(Ceshi('test_search'))
    suit.addTest(Ceshi('test_home'))
    now=time.strftime('%Y%m%d%H%M',time.localtime(time.time())) #'%Y%m%d%H%M',time.localtime(time.time())
    file=r'report/report.html' #测试报告地址
    fb=open(file,'wb')
    runner = HTMLTestRunner.HTMLTestRunner(stream=fb,title='test_report',description='detail')
    runner.run(suit)
    fb.close()
    with open(file,'rb') as ob:
    main_body=ob.read()
    msg=MIMEMultipart() #添加容器
    body=MIMEText(main_body,'html','utf-8') #邮件正文
    msg['Subject']=u'测试完成'
    msg['sender']='xxxx' #发件人
    msg['receiver'] = 'xxx' #收件人
    msg.attach(body)
    #添加附件
    att=MIMEText(main_body,'bs64','utf-8')
    att['Content-Type']="application/octet-stream"
    att['Content-Disposition'] = 'attachment;filename="report.html"'
    msg.attach(att)
    try:
    smtp=smtplib.SMTP_SSL('smtp.qq.com',465) #扣扣邮件服务,端口=465
    except:
    smtp=smtplib.SMTP()
    smtp.connect('smtp.qq.com',465)
    smtp.login(msg['sender'],'password=xxx') #邮件服务登陆用户名,密码
    smtp.sendmail(msg['sender'],msg['receiver'],msg.as_string()) #发送邮件
    smtp.quit()
    print('mail send out')
    if __name__ == '__main__':
    run_main()
  • 相关阅读:
    Codeforces 405E DFS
    Codeforces 433C #248_div1_A 中位数的应用
    UVALive 4487 Exclusive-OR 加权并查集神题
    Codeforces 442A Borya and Hanabi
    人工智能:实现人工智能是是不可能的吗?
    关于kinect开发的网址
    jsp笔记(1)
    关于Kinect音频开发的探究
    windows10添加电源计划修改的快捷方案
    关于 kinect 的开发
  • 原文地址:https://www.cnblogs.com/zynzyf/p/9113403.html
Copyright © 2011-2022 走看看