Ranorex通过Python将报告发送到邮箱的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Ranorex通过Python将报告发送到邮箱的方法

  2021-04-02 我要评论

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上编写脚本发送邮箱最方便。

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们