이메일 메시지의 본문 부분에있는 이메일 코드에 일부 데이터를 보내려고합니다. 문자열을 반환하는 함수를 호출하고 목록을 반환하는 다른 함수를 호출하고 있습니다. 메시지 본문 부분에이를 포함시키고 싶습니다. 내가 오류 형식 오류를 얻고있다 :Python TypeError : 메일 본문의 'str'및 'list'객체를 연결할 수 없습니다.
이Traceback (most recent call last):
File "E:/test_runners 2 edit project in progress add more tests/selenium_regression_test_5_1_1/Email/email_selenium_report.py", line 32, in <module>
report.send_report_summary_from_htmltestrunner_selenium_report2()
File "E:\test_runners 2 edit project in progress add more tests\selenium_regression_test_5_1_1\Email\report.py", line 520, in send_report_summary_from_htmltestrunner_selenium_report2
extract_testcases_from_report_htmltestrunner()) + "\n Report location = : \\storage-1\Testing\Selenium_Test_Report_Results\ClearCore_5_1_1\Selenium VM\IE11 \n")
TypeError: cannot concatenate 'str' and 'list' objects
메시지 본문 부분이 내 이메일 코드의 라인
:
msg = MIMEText("\n ClearCore 5_1_1 Automated GUI Test_IE11_Selenium_VM \n " + extract_only_header_from_summary_from_report_htmltestrunner() + "\n extract_header_count__from_summary_from_report_htmltestrunner() \n" + list(
extract_testcases_from_report_htmltestrunner()) + "\n Report location = : \\storage-1\Testing\Selenium_Test_Report_Results\ClearCore_5_1_1\Selenium VM\IE11 \n")
내 이메일 코드는 'STR'과 '목록'개체에 연결할 수 없습니다 :
는from email.mime.text import MIMEText
def send_report_summary_from_htmltestrunner_selenium_report2():
print extract_only_header_from_summary_from_report_htmltestrunner()
print extract_header_count__from_summary_from_report_htmltestrunner()
all_testcases = list(extract_testcases_from_report_htmltestrunner())
# print all_data
pprint.pprint(all_testcases)
msg = MIMEText("\n ClearCore 5_1_1 Automated GUI Test_IE11_Selenium_VM \n " + extract_only_header_from_summary_from_report_htmltestrunner() + "\n extract_header_count__from_summary_from_report_htmltestrunner() \n" + list(
extract_testcases_from_report_htmltestrunner()) + "\n Report location = : \\storage-1\Testing\Selenium_Test_Report_Results\ClearCore_5_1_1\Selenium VM\IE11 \n")
msg['Subject'] = "ClearCore 5_1_1 Automated GUI Test"
msg['to'] = "riaz.ladhani[email protected]"
msg['From'] = "[email protected]"
s = smtplib.SMTP()
s.connect(host=SMTP_SERVER)
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.close()
목록을 반환 기능은 다음과 같습니다
def extract_testcases_from_report_htmltestrunner():
filename = (r"E:\test_runners 2 edit project\selenium_regression_test_5_1_1\TestReport\ClearCore501_Automated_GUI_TestReport.html")
html_report_part = open(filename,'r')
soup = BeautifulSoup(html_report_part, "html.parser")
for div in soup.select("#result_table tr div.testcase"):
yield div.text.strip().encode('utf-8'), div.find_next("a").text.strip().encode('utf-8')
내가 문자열을 반환하는 호출 오전 617,451,515,
다른이 개 기능은 다음과 같습니다
def extract_only_header_from_summary_from_report_htmltestrunner():
filename = (r"E:\test_runners 2 edit project\selenium_regression_test_5_1_1\TestReport\ClearCore501_Automated_GUI_TestReport.html")
html_report_part = open(filename,'r')
soup = BeautifulSoup(html_report_part, "html.parser")
table = soup.select_one("#result_table")
#Create list here...
results = []
headers = [td.text for td in table.select_one("#header_row").find_all("td")[1:-1]]
# print(" ".join(headers))
#Don't forget to append header (if you want)
results.append(headers)
return results
def extract_header_count__from_summary_from_report_htmltestrunner():
filename = (r"E:\test_runners 2 edit project\selenium_regression_test_5_1_1\TestReport\ClearCore501_Automated_GUI_TestReport.html")
html_report_part = open(filename,'r')
soup = BeautifulSoup(html_report_part, "html.parser")
table = soup.select_one("#result_table")
#Create list here...
results = []
for row in table.select("tr.passClass"):
#Store row string in variable and append before printing
row_str = " ".join([td.text for td in row.find_all("td")[1:-1]])
results.append(row_str)
# print(row_str)
return results
내가 전자 메일 메시지의 본문 부분으로 이러한 기능의 데이터를 포함 할 수 있습니다 어떻게
? 문자열을 연결하려고했으나 문자열과 목록을 연결할 수 없다는 메시지가 표시되어 작동하지 않았습니다.
감사합니다, 리아 즈
나는 extract_only_header_from_summary_report_htmltestrunner 함수를 사용해 보았습니다. 오류가 발생했습니다. TypeError : 시퀀스 항목 0 : 예상 문자열, 목록을 찾았습니다. –
오류로 강조 표시된 행은 '\ n'에 있습니다. 조인 (결과) –
@RiazLadhani Oh. 나는 결과가 목록의 목록이라는 사실을 놓쳤다. 그러나 그것이 필요하지는 않은 것으로 보인다. 'results' 변수를 제거하고 \ n'.join (headers)'를 리턴 할 수 있습니다. – DeepSpace