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()
  • 相关阅读:
    Failed setting up proxy interface org.apache.hadoop.hbase.ipc.HRegionInterface
    关于操作权限
    什么时候才应该使用HBase?
    模块化服务规范——OSGI
    15个你可能不知道的开源云平台
    hadoop 异常记录 ERROR: org.apache.hadoop.hbase.MasterNotRunningException: Retried 7 times
    Apache nutch1.5 & Apache solr3.6
    Apache cassandra
    谈谈SAAS模式
    卸载VisualStudio插件
  • 原文地址:https://www.cnblogs.com/zynzyf/p/9113403.html
Copyright © 2011-2022 走看看