使用python3实现-发送robot framework 概要报告邮件

本文介绍如何在Python3环境下,通过读取Robot Framework的log.html或output.xml文件,提取数据并组装HTML模板,最后使用SMTP协议发送包含报告的HTML格式邮件。
摘要由CSDN通过智能技术生成

robot运行完成后会生成三个文件,现想发送log.html中的三个表格邮件,由于该日志是JS格式,所以直接发送,邮件会提示打开robot报告失败。可以通过读取log.html或者output.xml文件来提取所需数据信息,然后自己组装html格式文件。主要由以下几个步骤:
1、读取log.html,使用正则提取三个表格中的数据内容
2、组装html模板
3、使用smtp协议发送html格式的邮件内容,也可以带附件
直接上代码:

# -*- coding: utf-8 -*-
# @Time    : 2020/6/15 10:27
# @Author  : 
# @desc    : 
import time
import smtplib
import email
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.header import Header
from email.mime.multipart import MIMEMultipart
import os.path
import re
from bs4 import BeautifulSoup


class SendEmail(object):
    def __init__(self):
        self.log_path = self.get_log_path('log.html')
        self.report_path = self.get_log_path('report.html')
        self.head = '''
        <head><style type="text/css">
        .report_style{margin:20px 10%}        
        .header{text-align:center;width:100%;font-family:"Times New Roman"}    
        .report_table {text-align:center; width:100%; font-family:"Times New Roman"}        
        .report_table_title  {height:40px; text-align:center; width:100%; font-weight: bold; font-size:24px} 
       
        .report_table_content {background-color:#99CCFF; width:27%; text-align:center; padding:0 10px;} 
        .report_table_total {background-color:#CCFFFF; width:18%; text-align:center; padding:0 10px;}
        .table_content_success {background-color: #6bff8f; width:16%; text-align:center; padding:0 10px;}        
        .table_content_fail {background-color: #ff6c6d; width:15%; text-align:center; padding:0 10px;}
        .table_elapsed_time {background-color:#99CCFF; width:24%; text-align:center; padding:0 10px;}
        .table_head {background-color: #66CCFF; text-align:center; font-weight:bold; padding:0 10px;} 
        .table_path {background-color:#FFCC99; width:0%; text-align:center; padding:0 10px;}
        </style></head> 
         <div class="header"><h1>自动化测试报告</h1></div>
        '''

        self.table_head = '''<div class="report_style"><table class="report_table">
        <tr><th colspan="6" class="report_table_title">table_title_name</th></tr>
        <br>
        <tr><td class="table_head">name</td><td class="table_head">Total</td><td class="table_head">Pass</td><td class="table_head">Fail</td><td class="table_head">Elapsed Time</td></tr>
        '''
        self.table_content = '<tr>&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值