美文网首页
appium+python自动发送测试报告邮件

appium+python自动发送测试报告邮件

作者: DuffyMagic | 来源:发表于2019-08-21 15:15 被阅读0次

appium+python测试用例执行完成后,可将测试用例发送到指定邮箱

import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


class SendNewReport:
    def sendmail(self):
        smtpserver = 'smtp.qq.com'
        user = '你的发送邮箱 '
        password = '邮箱通行码'
        sender = '你的发送邮箱'
        receiver = '接收邮箱'

        subject = 'iOS UI自动化测试报告'
        # 测试报告存储路径
        report_dir = "/Users/liyaoyao/Documents/basebbs-all-autotest/iOSAutoTest/iOSAppiumTest/iOSTest/TestReport/"
        # 将测试报告文件夹下的所有文件名作为一个列表返回
        lists = os.listdir(report_dir)
        # 对所有测试报告按照生成时间进行排序
        lists.sort(key=lambda filename: os.path.getmtime(
            "/Users/liyaoyao/Documents/basebbs-all-autotest/iOSAutoTest/iOSAppiumTest/iOSTest/TestReport/" + filename))
        # 获取最新的测试报告
        recent = lists[-1]
        print(report_dir + recent)
        # 指定最新的测试报告路径
        # file = os.path.join(report_dir, recent).read()
        sendfile = open(report_dir + recent, 'rb').read()

        # 发送带附件的邮件
        attach = MIMEText(sendfile, 'base64', 'utf-8')
        attach['Content-Type'] = 'application/octet-stream'
        attach['Content-disposition'] = 'attachment; filename = "test.html" '  # 邮件上显示的附件名称

        msgRoot = MIMEMultipart('related')
        msgRoot['Subject'] = subject
        msgRoot['html']
        msgRoot.attach(attach)

        smtp = smtplib.SMTP()
        smtp.connect(smtpserver)
        smtp.login(user, password)
        smtp.sendmail(sender, receiver, msgRoot.as_string())
        smtp.quit()

相关文章

网友评论

      本文标题:appium+python自动发送测试报告邮件

      本文链接:https://www.haomeiwen.com/subject/gzzbsctx.html