diff --git a/README.md b/README.md index 51a644b6d4852d13de0283e8a5bc19a6b3ae6545..2f958d7eaf6c72a6c41413a83c70394949a20ba6 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,5 @@ ---------------------------------------------------------------------------- 实际报告如图,分别展现了一个执行失败Case的报错信息+截图,一个执行通过Case的运行日志。 -readme_report.png ![readme_report.png](https://github.com/songzhenhua/selenium_ui_auto/blob/master/readme_report.png) diff --git a/config/config.py b/config/config.py index c9477a49ee8350d47984d1693fc664c330e5bc79..d24bf761f9c4036c8e7aa562c6143c6a3a7c30db 100644 --- a/config/config.py +++ b/config/config.py @@ -22,8 +22,8 @@ def init(): _global_dict['download_path'] = "{}\\file\\download\\".format(root_dir) # 上传文件夹 _global_dict['upload_path'] = "{}\\file\\upload\\".format(root_dir) - # 存放日志路径 - _global_dict['log_path'] = "{}\\report\\".format(root_dir) + # 存放报告路径 + _global_dict['report_path'] = "{}\\report\\".format(root_dir) # 保存driver _global_dict['driver'] = None diff --git a/config/config.pyc b/config/config.pyc index 40cb83a04d4c5e1aa3e15ff416d561fd7feabe38..5d9f5dfcdd2ac328db8a991a0cdbd3a676b4c22e 100644 Binary files a/config/config.pyc and b/config/config.pyc differ diff --git "a/file/screenshot/test_home@test_click_news\346\211\223\345\274\200\346\226\260\351\227\273.png" "b/file/screenshot/test_home@test_click_news\346\211\223\345\274\200\346\226\260\351\227\273.png" index 7672d7524a464d1a4afec2f5b8e3c8c54cf4387a..7f4b2754661431cb13ebe0a38e7cf482e6a9b2a9 100644 Binary files "a/file/screenshot/test_home@test_click_news\346\211\223\345\274\200\346\226\260\351\227\273.png" and "b/file/screenshot/test_home@test_click_news\346\211\223\345\274\200\346\226\260\351\227\273.png" differ diff --git "a/file/screenshot/test_home@test_input_keyword\350\276\223\345\205\245\345\205\263\351\224\256\345\255\227\350\267\263\350\275\254.png" "b/file/screenshot/test_home@test_input_keyword\350\276\223\345\205\245\345\205\263\351\224\256\345\255\227\350\267\263\350\275\254.png" index 571f0734ef8e36c9df91e2d54fc069b3f8d52e3b..8c2531c59157601ab355f6b0745d24ae79b682fc 100644 Binary files "a/file/screenshot/test_home@test_input_keyword\350\276\223\345\205\245\345\205\263\351\224\256\345\255\227\350\267\263\350\275\254.png" and "b/file/screenshot/test_home@test_input_keyword\350\276\223\345\205\245\345\205\263\351\224\256\345\255\227\350\267\263\350\275\254.png" differ diff --git "a/file/screenshot/test_home@test_open_homepage\346\211\223\345\274\200\347\231\276\345\272\246\351\246\226\351\241\265.png" "b/file/screenshot/test_home@test_open_homepage\346\211\223\345\274\200\347\231\276\345\272\246\351\246\226\351\241\265.png" index 2c6d4d48dc5b5d7b30fe1ca7749fc5f7448cf485..0b5c6005671f43c450fac7b03081c61fbf78387f 100644 Binary files "a/file/screenshot/test_home@test_open_homepage\346\211\223\345\274\200\347\231\276\345\272\246\351\246\226\351\241\265.png" and "b/file/screenshot/test_home@test_open_homepage\346\211\223\345\274\200\347\231\276\345\272\246\351\246\226\351\241\265.png" differ diff --git "a/file/screenshot/test_news@test_search_news\346\220\234\347\264\242\346\226\260\351\227\273\345\244\261\350\264\245.png" "b/file/screenshot/test_news@test_search_news\346\220\234\347\264\242\346\226\260\351\227\273\345\244\261\350\264\245.png" index 0a17e496b733f264148da07f448cc6f0eaa67447..75d68994868dd2425c9635f093b0091f2e79a878 100644 Binary files "a/file/screenshot/test_news@test_search_news\346\220\234\347\264\242\346\226\260\351\227\273\345\244\261\350\264\245.png" and "b/file/screenshot/test_news@test_search_news\346\220\234\347\264\242\346\226\260\351\227\273\345\244\261\350\264\245.png" differ diff --git "a/file/screenshot/test_news@test_show_QRcode\346\230\276\347\244\272\344\272\214\347\273\264\347\240\201.png" "b/file/screenshot/test_news@test_show_QRcode\346\230\276\347\244\272\344\272\214\347\273\264\347\240\201.png" index 3a76072dcf9afc6521a0437c00e3af8793f09928..05542ba9074cae1d6c4b4a37339039258067b4e6 100644 Binary files "a/file/screenshot/test_news@test_show_QRcode\346\230\276\347\244\272\344\272\214\347\273\264\347\240\201.png" and "b/file/screenshot/test_news@test_show_QRcode\346\230\276\347\244\272\344\272\214\347\273\264\347\240\201.png" differ diff --git "a/file/screenshot/test_search@test_click_next_page\346\220\234\347\264\242\347\277\273\351\241\265.png" "b/file/screenshot/test_search@test_click_next_page\346\220\234\347\264\242\347\277\273\351\241\265.png" index c6746f48795fe1e0d00da769a308ac40adba6b60..09b4d4fef0f952f407956f58460b5f1cff31502d 100644 Binary files "a/file/screenshot/test_search@test_click_next_page\346\220\234\347\264\242\347\277\273\351\241\265.png" and "b/file/screenshot/test_search@test_click_next_page\346\220\234\347\264\242\347\277\273\351\241\265.png" differ diff --git "a/file/screenshot/test_search@test_click_next_page\346\220\234\347\264\242\347\277\273\351\241\265\345\244\261\350\264\245.png" "b/file/screenshot/test_search@test_click_next_page\346\220\234\347\264\242\347\277\273\351\241\265\345\244\261\350\264\245.png" deleted file mode 100644 index e724249af7b089d5bbc85e8d71c4fd641de10bd7..0000000000000000000000000000000000000000 Binary files "a/file/screenshot/test_search@test_click_next_page\346\220\234\347\264\242\347\277\273\351\241\265\345\244\261\350\264\245.png" and /dev/null differ diff --git "a/file/screenshot/test_search@test_click_result\346\211\223\345\274\200\346\220\234\347\264\242\347\273\223\346\236\234.png" "b/file/screenshot/test_search@test_click_result\346\211\223\345\274\200\346\220\234\347\264\242\347\273\223\346\236\234.png" index f8d2164cfb010f895ff3980570b2f3c01aa0cd2b..684079e7116c5fe3a7941fb5613b559c89f03279 100644 Binary files "a/file/screenshot/test_search@test_click_result\346\211\223\345\274\200\346\220\234\347\264\242\347\273\223\346\236\234.png" and "b/file/screenshot/test_search@test_click_result\346\211\223\345\274\200\346\220\234\347\264\242\347\273\223\346\236\234.png" differ diff --git "a/file/screenshot/test_search@test_click_result\346\211\223\345\274\200\346\220\234\347\264\242\347\273\223\346\236\234\345\244\261\350\264\245.png" "b/file/screenshot/test_search@test_click_result\346\211\223\345\274\200\346\220\234\347\264\242\347\273\223\346\236\234\345\244\261\350\264\245.png" deleted file mode 100644 index 88ce81a39ddfeafb3353aa0a61409fefc5afcb72..0000000000000000000000000000000000000000 Binary files "a/file/screenshot/test_search@test_click_result\346\211\223\345\274\200\346\220\234\347\264\242\347\273\223\346\236\234\345\244\261\350\264\245.png" and /dev/null differ diff --git a/report/report.html b/report/report.html index e222766e3e8b14a84bf44e37461537e03dccd4f1..829539cac0a2593a911e39b06b6885d91dc7a60f 100644 --- a/report/report.html +++ b/report/report.html @@ -398,7 +398,7 @@ function filter_table(elem) { }

report.html

-

Report generated on 18-Jan-2020 at 21:56:33 by pytest-html v1.22.0

+

Report generated on 25-Jan-2020 at 11:41:38 by pytest-html v1.22.0

Environment

@@ -417,7 +417,7 @@ function filter_table(elem) {
Python 2.7.10

Summary

-

9 tests ran in 20.64 seconds.

+

9 tests ran in 21.97 seconds.

8 passed, 0 skipped, 1 failed, 0 errors, 0 expected failures, 0 unexpected passes

Results

@@ -434,11 +434,11 @@ function filter_table(elem) { - + - + @@ -464,10 +464,10 @@ INFO szh.BasePage:base_page.py:355 截图:打开百度首页.png
Passed - + - + - + - + - + Passed - + Passed - +
Failed 新闻页-搜索新闻 test_case/test_news.py::TestSearch::test_search_news3.42
3.17
-
screenshot
-
self = <test_case.test_news.TestSearch instance at 0x0000000003DB8048>

def test_search_news(self):
"""新闻页-搜索新闻"""
try:
self.news_page.open_newspage()
self.news_page.search(u'涨工资') # 搜索涨工资
assert self.news_page.is_text_on_page(u'电视剧《一起来看流星雨》片头曲') # 故意断言失败
except Exception, e:
self.news_page.screenshot(u'搜索新闻失败')
> raise e
E AssertionError: assert False
E + where False = <bound method NewsPage.is_text_on_page of <page_object.news_page.NewsPage object at 0x00000000024FE9E8>>('电视剧《一起来看流星雨》片头曲')
E + where <bound method NewsPage.is_text_on_page of <page_object.news_page.NewsPage object at 0x00000000024FE9E8>> = <page_object.news_page.NewsPage object at 0x00000000024FE9E8>.is_text_on_page
E + where <page_object.news_page.NewsPage object at 0x00000000024FE9E8> = <test_case.test_news.TestSearch instance at 0x0000000003DB8048>.news_page

test_case\test_news.py:55: AssertionError
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:https://news.baidu.com/ +
screenshot
+
self = <test_case.test_news.TestSearch instance at 0x0000000003EE9148>

def test_search_news(self):
"""新闻页-搜索新闻"""
try:
self.news_page.open_newspage()
self.news_page.search(u'涨工资') # 搜索涨工资
assert self.news_page.is_text_on_page(u'电视剧《一起来看流星雨》片头曲') # 故意断言失败
except Exception, e:
self.news_page.screenshot(u'搜索新闻失败')
> raise e
E AssertionError: assert False
E + where False = <bound method NewsPage.is_text_on_page of <page_object.news_page.NewsPage object at 0x0000000003BCBA58>>('电视剧《一起来看流星雨》片头曲')
E + where <bound method NewsPage.is_text_on_page of <page_object.news_page.NewsPage object at 0x0000000003BCBA58>> = <page_object.news_page.NewsPage object at 0x0000000003BCBA58>.is_text_on_page
E + where <page_object.news_page.NewsPage object at 0x0000000003BCBA58> = <test_case.test_news.TestSearch instance at 0x0000000003EE9148>.news_page

test_case\test_news.py:55: AssertionError
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:http://news.baidu.com/ INFO szh.BasePage:base_page.py:56 等待元素:xpath,//input[@id="ww"] INFO szh.BasePage:base_page.py:75 获取元素:xpath,//input[@id="ww"] INFO szh.BasePage:base_page.py:119 向元素 xpath,//input[@id="ww"] 输入文字:涨工资 @@ -452,10 +452,10 @@ INFO szh.BasePage:base_page.py:355 截图:搜索新闻失败.png
Passed
首页-打开百度首页 test_case/test_home.py::TestHome::test_open_homepage1.55
1.34
-
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:https://www.baidu.com/ +
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:http://www.baidu.com/ INFO szh.BasePage:base_page.py:56 等待元素:xpath,//a[@name="tj_briicon"] INFO szh.TestHome:test_home.py:42 断言有‘更多产品’元素 成功 INFO szh.BasePage:base_page.py:355 截图:打开百度首页.png
首页-输入搜索关键字,自动跳转 test_case/test_home.py::TestHome::test_input_keyword1.78
1.83
-
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:https://www.baidu.com/ +
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:http://www.baidu.com/ INFO szh.BasePage:base_page.py:56 等待元素:xpath,//input[@id="kw"] INFO szh.BasePage:base_page.py:75 获取元素:xpath,//input[@id="kw"] INFO szh.BasePage:base_page.py:119 向元素 xpath,//input[@id="kw"] 输入文字:星空物语 @@ -480,10 +480,10 @@ INFO szh.BasePage:base_page.py:355 截图:输入关键字跳转.png
Passed
首页-打开新闻 test_case/test_home.py::TestHome::test_click_news2.19
2.57
-
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:https://www.baidu.com/ +
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:http://www.baidu.com/ INFO szh.BasePage:base_page.py:56 等待元素:xpath,//a[@name="tj_trnews"] INFO szh.BasePage:base_page.py:75 获取元素:xpath,//a[@name="tj_trnews"] INFO szh.BasePage:base_page.py:135 点击元素:xpath,//a[@name="tj_trnews"] @@ -495,10 +495,10 @@ INFO szh.BasePage:base_page.py:355 截图:打开新闻.png
Passed 首页-打开hao123 test_case/test_home.py::TestHome::test_click_hao1231.26
2.64
-
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:https://www.baidu.com/ +
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:http://www.baidu.com/ INFO szh.BasePage:base_page.py:56 等待元素:xpath,//a[@name="tj_trhao123"] INFO szh.BasePage:base_page.py:75 获取元素:xpath,//a[@name="tj_trhao123"] INFO szh.BasePage:base_page.py:135 点击元素:xpath,//a[@name="tj_trhao123"] @@ -509,10 +509,10 @@ INFO szh.TestHome:test_home.py:79 断言有‘腾讯链接’ 成功
Passed
新闻页-显示二维码 test_case/test_news.py::TestSearch::test_show_QRcode1.77
1.47
-
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:https://news.baidu.com/ +
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:http://news.baidu.com/ INFO szh.BasePage:base_page.py:56 等待元素:xpath,//li[@class="item qr-code button-rotate"] INFO szh.BasePage:base_page.py:75 获取元素:xpath,//li[@class="item qr-code button-rotate"] INFO szh.BasePage:base_page.py:162 指向元素xpath,//li[@class="item qr-code button-rotate"] @@ -523,7 +523,7 @@ INFO szh.BasePage:base_page.py:355 截图:显示二维码.png
Passed
新闻页-点击轮播图 test_case/test_news.py::TestSearch::test_click_carousel0.14
0.13
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:56 等待元素:xpath,//div[@id="imgView"] @@ -535,10 +535,10 @@ INFO szh.BasePage:base_page.py:363 关闭当前Tab
搜索页-点击首个搜索结果 test_case/test_search.py::TestSearch::test_click_result6.09
6.15
-
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:https://www.baidu.com/ +
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:102 打开网址:http://www.baidu.com/ INFO szh.BasePage:base_page.py:56 等待元素:xpath,//input[@id="kw"] INFO szh.BasePage:base_page.py:75 获取元素:xpath,//input[@id="kw"] INFO szh.BasePage:base_page.py:119 向元素 xpath,//input[@id="kw"] 输入文字:星空物语 @@ -554,7 +554,7 @@ INFO szh.BasePage:base_page.py:363 关闭当前Tab
搜索页-搜索翻页 test_case/test_search.py::TestSearch::test_click_next_page1.92
1.96
------------------------------ Captured log call -------------------------------
INFO szh.BasePage:base_page.py:56 等待元素:link,下一页> diff --git a/run.py b/run.py index 9a3ec59e7a4f1465e721adade92afd7433da7201..15193754f2064adcbd55a0b76f3ef88007730407 100644 --- a/run.py +++ b/run.py @@ -9,12 +9,13 @@ import config.config as cf from util.log import Logger import argparse from selenium import webdriver +from util.mail import send_mail def get_args(): """命令行参数解析""" parser = argparse.ArgumentParser(description=u'可选择参数:') - parser.add_argument('-e', '--environment', choices=['preview', 'product'], help=u'测试环境preview,线上环境product') + parser.add_argument('-e', '--environment', choices=['preview', 'product'], default='preview', help=u'测试环境preview,线上环境product') args = parser.parse_args() if args.environment in ('pre', 'preview'): cf.set_value('environment', 'preview') @@ -51,4 +52,7 @@ if __name__ == '__main__': log = Logger('szh') # 初始化log配置 set_driver() # 初始化driver main() # 运行pytest测试集 - cf.get_value('driver').quit() # 关闭selenium driver \ No newline at end of file + cf.get_value('driver').quit() # 关闭selenium driver + + # 先将util.mail文件send_mail()中的用户名、密码填写正确,再启用发送邮件功能!!! + # send_mail(['22459496@qq.com']) # 将报告发送至邮箱 diff --git a/util/mail.py b/util/mail.py new file mode 100644 index 0000000000000000000000000000000000000000..e89504556de730c07f62cff2b6ecbf56d686f705 --- /dev/null +++ b/util/mail.py @@ -0,0 +1,45 @@ +# coding=utf-8 +# @Time : 2020/1/25 10:49 +# @Author: zhenhua.song +# @File : mail.py +# @Description: 发送邮件 + +import smtplib +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +from email.header import Header +import config.config as cf + + +def send_mail(sendto): + """ + 发送邮件 + :param sendto:收件人列表,如['22459496@qq.com'] + """ + mail_host = 'smtp.sohu.com' # 邮箱服务器地址 + username = 'test@sohu.com' # 邮箱用户名 + password = 'test' # 邮箱密码 + receivers = sendto # 收件人 + + # 创建一个带附件的实例 + message = MIMEMultipart() + message['From'] = Header(u'UI自动化', 'utf-8') + message['subject'] = Header(u'UI自动化测试结果', 'utf-8') # 邮件标题 + message.attach(MIMEText(u'测试结果详见附件', 'plain', 'utf-8'))# 邮件正文 + # 构造附件 + report_root = cf.get_value('report_path') # 获取报告路径 + report_file = 'report.html' # 报告文件名称 + att1 = MIMEText(open(report_root + report_file, 'rb').read(), 'base64', 'utf-8') + att1["Content-Type"] = 'application/octet-stream' + att1["Content-Disposition"] = 'attachment; filename={}'.format(report_file) + message.attach(att1) + + try: + smtp = smtplib.SMTP() + smtp.connect(mail_host, 25) # 25为 SMTP 端口号 + smtp.login(username, password) + smtp.sendmail(username, receivers, message.as_string()) + print u'邮件发送成功' + except Exception, e: + print u'邮件发送失败' + raise e