zoukankan      html  css  js  c++  java
  • selenium封装 运行脚本+生成测试报告+发送email

    
    
    #conding:utf-8
    import smtplib
    from email.mime.text import  MIMEText #导入MIMEText html模板
    from email.mime.multipart import MIMEMultipart
    
    import unittest
    from HTMLTestRunner import HTMLTestRunner
    import smtplib
    from email.mime.text import  MIMEText #导入MIMEText html模板
    
    def test_Run_report():
        #指定测试用例为当前文件夹下的test_Case目录,并匹配测试脚本
        discover = unittest.defaultTestLoader.discover(start_dir="D:\python\testcase",pattern="test*.py",top_level_dir=None)
        #定义报告存储路径
        reportPath="D:\python\report\"+"TestReport.html"
        #定义写入文件路径和方法
        fp=open(reportPath,"w")
        #将报告写入到定义的文件中
        runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title=u"testreport",verbosity=2,description="testcase")
        # 执行测试用例
        runner.run(discover)
    
    
    
    def test_send_email():
    
        #1.参数配置
        smtpserver="smtp.qq.com"#发件服务器
        port=465#端口
        sender="504527497@qq.com"#发件人
        psw="tkyujpdduawmbgfc"  #授权码 QQ邮箱需要,其他不一定
        receiver="504527497@qq.com"#收件人
    
        #2.编写邮件html模板,发送=附件方法
        msg = MIMEMultipart()
        msg['Subject']  ="这是测试报告"
        msg['From']=sender
        msg['To']=receiver
        f=open("D:\python\report\TestReport.html")
        mail_body=f.read()
        f.close()
        #添加附件
        att = MIMEText(mail_body,"base64", "utf-8")
        att["Content-Type"] = "application/octet-stream"
        att["Content-Disposition"] = 'attachment; filename="TestReport.html"'
        msg.attach(att)
        #加正文
        body = MIMEText(mail_body,'html','utf-8')
        msg.attach(body)
    
    
        #3.发送邮件
        smtp =smtplib.SMTP_SSL(smtpserver,port)
        smtp.login(sender,psw)
        smtp.sendmail(sender,receiver,msg.as_string())
        smtp.quit()
    
    test_Run_report()
    test_send_email()
    
    
    
     
  • 相关阅读:
    访问者模式
    oracle触发器简单实用示例
    C#控件交互效果类(也可以用作缩小面板放大,展示更多信息)
    23种设计模式探索C#
    windows快捷操作个人记录(常用)
    C#巧妙使用关键字async/await
    学习的枚举类型,结构以及初步了解数组
    目前学习.net时间让我摸不着头脑的事情
    对C#中几个循环语句的使用,请教
    学习了用控制台显示结果
  • 原文地址:https://www.cnblogs.com/onelove1/p/13111259.html
Copyright © 2011-2022 走看看