Ranorex通過Python將報告發送到郵箱的方法
阿新 • • 發佈:2020-01-13
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上編寫指令碼傳送郵箱最方便。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。