├── python.exe
├── screenshot
├── 领取京豆.jpg
├── 京东金融签到.jpg
├── 掌上生活签到.jpg
├── 京东金融提额包.jpg
├── 网易云音乐签到.jpg
└── 联通营业厅签到.jpg
├── __pycache__
├── schedule.cpython-35.pyc
├── test_apps.cpython-35.pyc
├── get_device.cpython-35.pyc
├── HTMLTestRunner.cpython-35.pyc
├── appium_server.cpython-35.pyc
└── appium_service.cpython-35.pyc
├── public
├── __pycache__
│ ├── get_device.cpython-35.pyc
│ ├── schedule.cpython-35.pyc
│ └── appium_server.cpython-35.pyc
├── get_device.py
└── schedule.py
├── start_appium_server.bat
├── stop_appium_server.bat
├── .idea
├── vcs.xml
├── misc.xml
├── modules.xml
├── daily_task.iml
└── workspace.xml
├── appium_server.py
├── README.md
├── run.py
├── report
└── 2017-12-12 result.html
├── test_apps.py
└── HTMLTestRunner.py
/python.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/python.exe
--------------------------------------------------------------------------------
/screenshot/领取京豆.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/screenshot/领取京豆.jpg
--------------------------------------------------------------------------------
/screenshot/京东金融签到.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/screenshot/京东金融签到.jpg
--------------------------------------------------------------------------------
/screenshot/掌上生活签到.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/screenshot/掌上生活签到.jpg
--------------------------------------------------------------------------------
/screenshot/京东金融提额包.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/screenshot/京东金融提额包.jpg
--------------------------------------------------------------------------------
/screenshot/网易云音乐签到.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/screenshot/网易云音乐签到.jpg
--------------------------------------------------------------------------------
/screenshot/联通营业厅签到.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/screenshot/联通营业厅签到.jpg
--------------------------------------------------------------------------------
/__pycache__/schedule.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/__pycache__/schedule.cpython-35.pyc
--------------------------------------------------------------------------------
/__pycache__/test_apps.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/__pycache__/test_apps.cpython-35.pyc
--------------------------------------------------------------------------------
/__pycache__/get_device.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/__pycache__/get_device.cpython-35.pyc
--------------------------------------------------------------------------------
/__pycache__/HTMLTestRunner.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/__pycache__/HTMLTestRunner.cpython-35.pyc
--------------------------------------------------------------------------------
/__pycache__/appium_server.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/__pycache__/appium_server.cpython-35.pyc
--------------------------------------------------------------------------------
/__pycache__/appium_service.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/__pycache__/appium_service.cpython-35.pyc
--------------------------------------------------------------------------------
/public/__pycache__/get_device.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/public/__pycache__/get_device.cpython-35.pyc
--------------------------------------------------------------------------------
/public/__pycache__/schedule.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/public/__pycache__/schedule.cpython-35.pyc
--------------------------------------------------------------------------------
/public/__pycache__/appium_server.cpython-35.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtfghd/AppTask/HEAD/public/__pycache__/appium_server.cpython-35.pyc
--------------------------------------------------------------------------------
/start_appium_server.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | title start_appium_server
3 | cmd /c "appium -a 127.0.0.1 -p 4723 -bp 4728 --chromedriver-port 9519 -U emulator-5554"
--------------------------------------------------------------------------------
/stop_appium_server.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | title stop_appium_server
3 | tasklist -v | find "start_appium_server">nul
4 | if %errorlevel%==0 (
5 | taskkill -fi "WINDOWTITLE eq start_appium_server"
6 | )
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 | JDK (1.8.0_91)
8 | SDK (25.1.7)
9 | python 3
10 | node.js (v6.11.0)
11 | appium server (1.4.16)
12 | Appium-Python-Client (0.24)
13 | 雷电安卓模拟器(安卓5.1.1,720*1280)
14 |
15 |
16 | # 目录概览
17 | ```
18 | │ run.py
19 | │ appium_server.py
20 | │ test_apps.py
21 | │ HTMLTestRunner.py
22 | │ python.exe
23 | │ README.md
24 | │ start_appium_server.bat
25 | │ stop_appium_server.bat
26 | ├─public
27 | │ │ get_device.py
28 | │ │ schedule.py
29 | ├─report
30 | │ 2017-12-12 result.html
31 | ├─screenshot
32 | │ 京东金融签到.jpg
33 | │ 网易云音乐签到.jpg
34 | ```
35 |
36 | - `run.py` 启动整个项目就运行这个文件
37 | - `appium_server.py` 里面有两个函数,执行启动/关闭appium服务批处理文件的命令
38 | - `test_apps.py` 所有的APP任务在这个文件,每个APP是一个函数,都以test开头
39 | - `HTMLTestRunner.py` 用来生成html测试报告
40 | - `start_appium_server.bat` 启动appium服务的批处理文件
41 | - `stop_appium_server.bat` 关闭appium服务的批处理文件
42 | - [ public ] 放一些执行每个任务都会用到的公共文件,包括启动/关闭安卓模拟器脚本,以及项目进度说明。
43 | - [ report ] 任务执行结果以html格式的报告放在在这个目录
44 | - [ screenshot ] 执行APP任务时的截图放在目录
45 |
--------------------------------------------------------------------------------
/run.py:
--------------------------------------------------------------------------------
1 | #coding=utf-8
2 | import unittest,time,os
3 | from HTMLTestRunner import HTMLTestRunner
4 | from test_apps import *
5 | from public.get_device import *
6 | from public.schedule import *
7 | from appium_server import *
8 | import smtplib
9 | from email.mime.text import MIMEText
10 | from email.header import Header
11 | from email.mime.multipart import MIMEMultipart
12 |
13 | test_path = 'E:/daily_task_2'
14 | report_path = 'E:/daily_task_2/report/'
15 |
16 | def run_tasks():
17 | '''执行所有APP任务'''
18 | discover = unittest.defaultTestLoader.discover(test_path, pattern='test_*.py')
19 | now = time.strftime('%Y-%m-%d')
20 | filename = report_path + now + ' result.html' # 这个filename是生成的自动化测试报告的文件名
21 | fp = open(filename, 'wb')
22 | runner = HTMLTestRunner(stream=fp, title='测试报告', description='用例的执行情况')
23 | runner.run(discover)
24 | fp.close()
25 |
26 |
27 | def send_mail():
28 | '''任务完成后发送邮件通知'''
29 | # ----------找到当天的执行报告----------
30 | lists = os.listdir(report_path)
31 | for i in lists:
32 | now = time.strftime('%Y-%m-%d')
33 | if now in i:
34 | AppTaskReport = os.path.join(report_path, i) # 获取html格式的测试报告
35 | else:
36 | pass
37 |
38 | # ----------创建一个带附件的实例----------
39 | msg = MIMEMultipart()
40 | msg['Subject'] = Header('AppDailyTask', 'utf-8')
41 | msg['From'] = Header('peili', 'utf-8')
42 | msg['To'] = Header('peili', 'utf-8')
43 |
44 | # 添加邮件正文内容
45 | main_body_info = '''
46 |
47 |
绿色代表该APP任务执行成功并断言正确
49 |橙色代表该APP任务执行成功但断言错误,请查看截图文件或者打开APP确认任务是否完成
50 |红色代表任务执行失败,可能是APP有更新,页面突然有活动/广告弹窗或者网络问题导致,请检查网络和APP
51 | ''' 52 | msg.attach(MIMEText(main_body_info, 'html', 'utf-8')) 53 | 54 | # 添加附件 55 | file1 = MIMEText(open(AppTaskReport, 'rb').read(), 'plain', 'utf-8') 56 | file1['Content-Type'] = 'application/octet-stream' 57 | file1["Content-Disposition"] = 'attachment; filename="AppTaskReport.html"' # 这里的filename就是邮件中附件的名字,可以自己命名 58 | msg.attach(file1) 59 | 60 | 61 | # ----------登录并发送---------- 62 | try: 63 | smtp = smtplib.SMTP_SSL('smtp.qq.com', 465) # QQ邮箱发送服务器以及端口,SMTP默认端口是25,这里改成465 64 | smtp.login('123456789@qq.com', '********') # 如果是QQ邮箱的话,第二个参数不是直接用的密码,用的是QQ邮箱的授权码 65 | smtp.sendmail('123456789@qq.com', '123456789@qq.com', msg.as_string()) # 前两个参数分别是发送邮箱和接收邮箱 66 | smtp.quit() 67 | print('邮件发送成功') 68 | except smtplib.SMTPException as e: 69 | print(e) 70 | 71 | 72 | if __name__ == '__main__': 73 | 74 | process() #打印当前开发进度 75 | start_appium_server() #启动appium服务 76 | start_android_devices() #启动模拟器 77 | time.sleep(15) 78 | run_tasks() #执行APP任务 79 | send_mail() #发送邮件 80 | stop_android_devices() #关闭模拟器 81 | stop_appium_server() # 关闭appium服务 82 | -------------------------------------------------------------------------------- /report/2017-12-12 result.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |Start Time: 2017-12-12 10:43:40
193 |Duration: 0:00:56.222428
194 |Status: Failure 1
195 | 196 |用例的执行情况
197 |Show 202 | Summary 203 | Failed 204 | All 205 |
206 || Test Group/Test case | 217 |Count | 218 |Pass | 219 |Fail | 220 |Error | 221 |View | 222 |
| test_apps.AppTask | 226 |1 | 227 |0 | 228 |1 | 229 |0 | 230 |Detail | 231 |
test_005_zssh: 掌上生活每日签到 |
235 |
236 |
237 |
238 |
239 | fail
240 |
241 |
242 |
259 |
260 |
261 |
243 |
244 | [x]
245 |
246 |
247 |
248 | ft1.1: D:\Application\python35\lib\site-packages\selenium\webdriver\remote\webdriver.py:882: UserWarning: name used for saved screenshot does not match file type. It should end with a `.png` extension
249 | "type. It should end with a `.png` extension", UserWarning)
250 | 签到完成
251 | Traceback (most recent call last):
252 | File "E:\daily_task_2\test_apps.py", line 237, in test_005_zssh
253 | self.assertIn('领取成功', driver.page_source, msg='任务有失败,请到截图目录查看截图')
254 | AssertionError: '领取成功' not found in '<?xml version="1.0" encoding="UTF-8"?><hierarchy rotation="0"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[40,474][680,856]" resource-id="" instance="0"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[40,474][680,856]" resource-id="" instance="1"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[40,474][680,856]" resource-id="android:id/content" instance="2"><android.widget.RelativeLayout index="0" text="" class="android.widget.RelativeLayout" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[40,474][680,856]" resource-id="" instance="0"><android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[60,494][660,836]" resource-id="" instance="0"><android.widget.TextView index="0" text="提示" class="android.widget.TextView" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[320,534][400,588]" resource-id="com.cmbchina.ccd.pluto.cmbActivity:id/tv_title" instance="0"/><android.widget.TextView index="1" text="已经领过啦!明天再来签到可以获得抽奖资格哦!" class="android.widget.TextView" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[90,608][630,689]" resource-id="com.cmbchina.ccd.pluto.cmbActivity:id/tv_content" instance="1"/><android.view.View index="2" text="" class="android.view.View" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[60,729][660,731]" resource-id="com.cmbchina.ccd.pluto.cmbActivity:id/view_weight" instance="0"/><android.widget.LinearLayout index="3" text="" class="android.widget.LinearLayout" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[60,731][660,836]" resource-id="com.cmbchina.ccd.pluto.cmbActivity:id/option_bar" instance="1"><android.widget.TextView index="0" text="确定" class="android.widget.TextView" package="com.cmbchina.ccd.pluto.cmbActivity" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[60,731][660,836]" resource-id="com.cmbchina.ccd.pluto.cmbActivity:id/tv_sure" instance="2"/></android.widget.LinearLayout></android.widget.LinearLayout></android.widget.RelativeLayout></android.widget.FrameLayout></android.widget.FrameLayout></android.widget.FrameLayout></hierarchy>' : 任务有失败,请到截图目录查看截图
255 |
256 |
257 |
258 | |
262 | ||||
| Total | 266 |1 | 267 |0 | 268 |1 | 269 |0 | 270 |271 | |