欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Ranorex通過(guò)Python將報(bào)告發(fā)送到郵箱的方法

 更新時(shí)間:2020年01月12日 16:50:52   作者:Liuxm_0522  
這篇文章主要介紹了Ranorex通過(guò)Python將報(bào)告發(fā)送到郵箱的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

Ranorex測(cè)試報(bào)告如何發(fā)送到郵箱在網(wǎng)上看了下,其實(shí)可以通過(guò)在Ranorex上或者VS調(diào)用編寫(xiě)發(fā)送郵箱代碼就可以執(zhí)行發(fā)送了,RX主要涉及到的開(kāi)發(fā)語(yǔ)言是C++或者.NET。但是我想用Python調(diào)用并發(fā)送,涉及到的應(yīng)用以及范圍會(huì)比較麻煩。因此,希望有廣大猿友能夠給點(diǎn)意見(jiàn)指點(diǎn)一二。

首先將Ranorex測(cè)試解決方案在Pycharm打開(kāi)。

然后新建一個(gè)文件夾用來(lái)放Python發(fā)送郵件的CODE。

'''發(fā)送給********@163.com'''
from email.mime.application import MIMEApplication
import smtplib
import os
 
 
def send_email(new_log):
  '''
  發(fā)送郵箱
  :param new_log: 最新的報(bào)告
  :return:
  '''
 
  file = open(new_log, 'rb')
  mail_content = file.read()
  file.close()
 
  # 發(fā)送方用戶(hù)信息
  send_user = '********@qq.com'
  send_password = '********'
 
  # 發(fā)送和接收
  sendUser = '********@qq.com'
  receive = '********@163.com'
 
  # 郵件內(nèi)容
  send_subject = 'Ranorex自動(dòng)化測(cè)試報(bào)告'
  msg = MIMEApplication(mail_content, 'rb')
  msg['Subject'] = send_subject
  msg.add_header('Content-Disposition', 'attachment', filename=new_log)
 
  try:
 
    # 登錄服務(wù)器
    smt = smtplib.SMTP('smtp.qq.com')
 
    # helo 向服務(wù)器標(biāo)識(shí)用戶(hù)身份
    smt.helo('smtp.qq.com')
    # 服務(wù)器返回確認(rèn)結(jié)果
    smt.ehlo('smtp.qq.com')
 
    smt.login(send_user, send_password)
    print('正在準(zhǔn)備發(fā)送郵件。')
    smt.sendmail(sendUser, receive, msg.as_string())
    smt.quit()
    print('郵件發(fā)送成功。')
 
  except Exception as e:
    print('郵件發(fā)送失?。?, e)
 
 
def new_report(report_dir):
  '''
  獲取最新報(bào)告
  :param report_dir: 報(bào)告文件路徑
  :return: file ---最新報(bào)告文件路徑
  '''
 
  # 返回指定路徑下的文件和文件夾列表。
  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__':
  # 報(bào)告路徑
  test_report = r'D:\學(xué)習(xí)筆記\Ranorex\Text\1105\text02\text02\Reports'
  # 獲取最新測(cè)試報(bào)告
  newLog = new_report(test_report)
  # 發(fā)送郵件報(bào)告
  send_email(newLog)

運(yùn)行后,郵件發(fā)送成功。

在Windows上,Ranorex報(bào)告打開(kāi)后結(jié)果顯示錯(cuò)誤。

自己嘗試在Ranorex解決方案中將一份報(bào)告復(fù)制粘貼到桌面上,打開(kāi)也是以上圖的錯(cuò)誤,原因可能需要在Ranorex解決方案中的環(huán)境條件,所以即使發(fā)送了也沒(méi)什么用處,只能提醒Ranorex解決方案已經(jīng)運(yùn)行結(jié)束。

最后還是在Ranorex上編寫(xiě)腳本發(fā)送郵箱最方便。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論