Ranorex通过Python将报告发送到邮箱的方法
作者:Liuxm_0522 时间:2021-08-17 03:57:43
Ranorex测试报告如何发送到邮箱在网上看了下,其实可以通过在Ranorex上或者VS调用编写发送邮箱代码就可以执行发送了,RX主要涉及到的开发语言是C++或者.NET。但是我想用Python调用并发送,涉及到的应用以及范围会比较麻烦。因此,希望有广大猿友能够给点意见指点一二。
首先将Ranorex测试解决方案在Pycharm打开。
然后新建一个文件夹用来放Python发送邮件的CODE。
'''发送给********@163.com'''
from email.mime.application import MIMEApplication
import smtplib
import os
def send_email(new_log):
'''
发送邮箱
:param new_log: 最新的报告
:return:
'''
file = open(new_log, 'rb')
mail_content = file.read()
file.close()
# 发送方用户信息
send_user = '********@qq.com'
send_password = '********'
# 发送和接收
sendUser = '********@qq.com'
receive = '********@163.com'
# 邮件内容
send_subject = 'Ranorex自动化测试报告'
msg = MIMEApplication(mail_content, 'rb')
msg['Subject'] = send_subject
msg.add_header('Content-Disposition', 'attachment', filename=new_log)
try:
# 登录服务器
smt = smtplib.SMTP('smtp.qq.com')
# helo 向服务器标识用户身份
smt.helo('smtp.qq.com')
# 服务器返回确认结果
smt.ehlo('smtp.qq.com')
smt.login(send_user, send_password)
print('正在准备发送邮件。')
smt.sendmail(sendUser, receive, msg.as_string())
smt.quit()
print('邮件发送成功。')
except Exception as e:
print('邮件发送失败:', e)
def new_report(report_dir):
'''
获取最新报告
:param report_dir: 报告文件路径
:return: file ---最新报告文件路径
'''
# 返回指定路径下的文件和文件夹列表。
lists = os.listdir(report_dir)
listLog = []
# print(lists)
for i in lists:
if os.path.splitext(i)[1] == '.rxlog':
# print(len(i))
# print(i)
listLog.append(i)
# print(listLog)
# print(listLog[-1])
fileNewLog = os.path.join(report_dir, listLog[-2])
return fileNewLog
if __name__ == '__main__':
# 报告路径
test_report = r'D:\学习笔记\Ranorex\Text\1105\text02\text02\Reports'
# 获取最新测试报告
newLog = new_report(test_report)
# 发送邮件报告
send_email(newLog)
运行后,邮件发送成功。
在Windows上,Ranorex报告打开后结果显示错误。
自己尝试在Ranorex解决方案中将一份报告复制粘贴到桌面上,打开也是以上图的错误,原因可能需要在Ranorex解决方案中的环境条件,所以即使发送了也没什么用处,只能提醒Ranorex解决方案已经运行结束。
最后还是在Ranorex上编写脚本发送邮箱最方便。
来源:https://blog.csdn.net/qq_39979646/article/details/103933737
标签:Ranorex,Python,邮箱
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
用ASP实现远程批量文件改名
2007-09-12 12:23:00
python中get和post有什么区别
2022-04-17 16:45:15
phar绕过phar与HALT实现文件上传功能
2023-05-25 06:47:36
和“登录”有关的事儿
2009-07-10 17:37:00
![](https://img.aspxhome.com/file/UploadPic/20097/10/p173-34s.png)
Python实现将wav转amr,并转换成hex数组
2023-06-29 08:18:59
![](https://img.aspxhome.com/file/2023/0/59650_0s.png)
pytorch 实现在预训练模型的 input上增减通道
2023-12-02 00:49:33
解析SQL server与asp 互操作的时间处理
2009-02-05 16:13:00
了解WEB页面工具语言XML(五)好处
2008-09-05 17:19:00
教你如何在CI框架中使用 .htaccess 隐藏url中index.php
2023-11-14 11:49:57
python Matplotlib绘图直线,折线,曲线
2023-01-12 13:44:09
![](https://img.aspxhome.com/file/2023/3/79433_0s.png)
Sqlserver 2000/2005/2008 的收缩日志方法和清理日志方法
2012-07-21 14:55:18
Python timeit模块的使用实践
2023-09-15 00:36:55
Python中利用ItsDangerous快捷实现数据加密
2022-06-09 23:24:41
![](https://img.aspxhome.com/file/2023/3/67283_0s.jpg)
pandas求两个表格不相交的集合方法
2022-03-08 01:15:41
![](https://img.aspxhome.com/file/2023/5/93525_0s.jpg)
从Vista地址栏到网站导航菜单
2009-09-08 12:35:00
![](https://img.aspxhome.com/file/UploadPic/20099/8/nav-62s.jpg)
Python+Selenium+Webdriver实现自动执行微软奖励积分脚本
2022-09-13 13:49:07
javascript分页代码实例分享(js分页)
2023-10-11 10:00:57
python 简易计算器程序,代码就几行
2021-05-23 22:28:32
python随机模块random使用方法详解
2022-07-02 04:31:10
Python中django学习心得
2023-12-24 17:10:15
![](https://img.aspxhome.com/file/2023/2/89322_0s.png)