Send Email in Robot Framework Python Using Gmail
转载自:http://seleniummaster.com/sitecontent/index.php/selenium-robot-framework-menu/selenium-robot-framework-python-menu/228-send-email-in-robot-framework-python-using-gmail
When using Robot Framework Python, some customized test result log files or report files need to be emailed to QA engineers. You can create custom Gmail Email Library to send email with attachment or no attachment.
Step 1: create a folder named "GmailEmailLibrary" under C:\Python27\Lib\site-packages (assuming that you have installed python at the root of C: drive)
C:\Python27\Lib\site-packages\GmailEmailLibrary
Step 2: write following codes in the file "gmailsendemail.py" and "__init__.py"
gmailsendemail.py
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os class SendEmailUtility(object): ROBOT_LIBRARY_SCOPE = 'Global' def __init__(self):
print 'send email utility' def send_mail_with_attachment(self,from_user,from_password,to, subject, text, attach):
msg = MIMEMultipart() msg['From'] = from_user
msg['To'] = to
msg['Subject'] = subject msg.attach(MIMEText(text)) part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition',
'attachment; filename="%s"' % os.path.basename(attach))
msg.attach(part) mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(from_user, from_password)
mailServer.sendmail(from_user, to, msg.as_string())
# Should be mailServer.quit(), but that crashes...
mailServer.close() def send_mail_no_attachment(self,from_user,from_password,to, subject, text):
msg = MIMEMultipart() msg['From'] = from_user
msg['To'] = to
msg['Subject'] = subject msg.attach(MIMEText(text)) mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(from_user, from_password)
mailServer.sendmail(from_user, to, msg.as_string())
# Should be mailServer.quit(), but that crashes...
mailServer.close()
__init__.py
from gmailsendemail import SendEmailUtility
__version__ = '1.0' class GmailEmailLibrary(SendEmailUtility): ROBOT_LIBRARY_SCOPE = 'GLOBAL'
Step 3: create a test project using RIDE in robot framework as shown below. Make sure that you import the library "GmailEmailLibrary".
Step 4: create the test cases "Send Email Has Attachment Test" and "Send Email No Attachment Test". See the text version below.
*** Settings ***
Library GmailEmailLibrary *** Test Cases ***
Send Email Has Attachment Test
Send Mail With Attachment
services@seleniummaster.com **********
test@test.com Python Email Test This is python test test.txt Send Email No Attachment Test
Send Mail No Attachment
services@seleniummaster.com **********
test@test.com This is a test, this is a test Test is in progress
Run the tests. The two test cases will pass
Send Email in Robot Framework Python Using Gmail的更多相关文章
- 关于《自动化测试实战宝典:Robot Framework + Python从小工到专家》
受新冠疫情影响,笔者被“困”在湖北老家七十余天,于4月1号(愚人节)这天,终于返回到广州.当前国内疫情基本已趋于平稳,但全球疫情整体势态仍在持续疯涨,累计确诊病例已近80万人.祈祷这场全球性灾难能尽早 ...
- Robot Framework+python的安装,配置,环境搭建(纯白篇)
弄了大半天 终于把-Robot Framework-弄好了,总是一个发现问题,一个一个去解决的过程,只是时间嘛,咳咳咳咳 言归正传 第一. 记住了 Robot Framework 的库 只支持 pyt ...
- 【转】robot framework + python实现http接口自动化测试框架
前言 下周即将展开一个http接口测试的需求,刚刚完成的java类接口测试工作中,由于之前犯懒,没有提前搭建好自动化回归测试框架,以至于后期rd每修改一个bug,经常导致之前没有问题的case又产生了 ...
- robot framework + python实现http接口自动化测试框架
https://www.jianshu.com/p/6d1e8cb90e7d 前言 下周即将展开一个http接口测试的需求,刚刚完成的java类接口测试工作中,由于之前犯懒,没有提前搭建好自动化回归测 ...
- Robot framework+python安装使用图解版
一.安装包 1.Python2.7(一切的基础,切记安装目录不能有中文不能有空格) 1)python2.7:(python环境):python-2.7.msi 2)setuptools(python包 ...
- 用Robot Framework+python来测试基于socket通讯的C/S系统(网络游戏)
项目终于换了方案,改用socket来实现而不是之前的http了,所以测试工具就不能用以前的了,因为测试人手少,逼不得已的必须要挖掘更多的自动化方案来弥补.于是先研究了下python的socket解决方 ...
- Robot Framework环境搭建(问题总结)
Robot Framework+python+wxpython+robotframework-ride+library环境搭建问题总结 因为robotframework的兼容性问题要求很严格,小编在环 ...
- Robot Framework通过Python SMTP进行email收发测试。
工作中需要对发送的邮件进行过滤,方法基本属于ACL控制,即查看“源/目的”邮件地址,邮件标题,邮件正文,邮件附件等进行过滤. 所以需要先模拟一下用Python能否达到邮件Client,Server的功 ...
- robot framework用python扩展编写自定义library
我的utils.py文件 #!/usr/bin/env python #-*- coding:utf8 -*- __version__ = '0.1' import sys reload(sys) s ...
随机推荐
- c# throw抛出上一个异常
catch(exception e) { throw; } 不仅抛出这次的异常,也抛出之前的异常. 用法示例:函数A调用函数B,A用到此throw时,B中发生的异常也会继承过来. catch(exce ...
- 寒假作业end
开始写博客的个人体会 自己打的链表过不了,果然,心存侥幸是不行的,被揪出来也不错,很感谢畅畅酱. 学术诚信的重要性 爱因斯坦说过:"大多数人说是才智造就了伟大的科学家,他们错了,是人格.&q ...
- .net改善程序性能建议
对改善程序性能的建议. 文章:https://msdn.microsoft.com/zh-cn/library/ms973838.aspx
- MFC修改视图CView的背景颜色
(1) 在CYournameView(就是你的视图类,以下以CDrawLineView为例)添加了一个背景颜色变量 COLORREF m_bgcolor; (2)修改这个函数: BOOL CDrawL ...
- TCP系列34—窗口管理&流控—8、缓存自动调整
一.概述 我们之前介绍过一种具有大的带宽时延乘积(band-delay product.BDP)的网络,这种网络称为长肥网络(LongFatNetwork,即LFN).我们想象一种简单的场景,假设发送 ...
- CEntOS6.5从启动界面直接进入命令行界面
ctrl + alt + F1 ctrl + alt + F2 ctrl + alt + F3 ctrl + alt + F4 ctrl + alt + F5 ctrl + alt + F6 同时按下 ...
- delphi鼠标状态
Screen.Cursor := crNo;
- Wannafly 挑战赛16 A 取石子
题目描述 给出四堆石子,石子数分别为a,b,c,d.规定每次只能从堆顶取走石子,问取走所有石子的方案数. 输入描述: 在一行内读入四个由空格分隔的整数a,b,c,d, 输入均为不超过500的正整数 输 ...
- Runtime之字典转模型实战
Runtime之字典转模型实战 先来看看怎么使用Runtime给模型类赋值 iOS开发中的Runtime可谓是功能强大,同时Runtime使用起来也是非常灵活的,今天博客的内容主要就是使用到一丁点的R ...
- hdu 1596 find the safest road (最短路径)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...