-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrun.py
70 lines (61 loc) · 2.24 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess,sys
from monkey.getbasic import GetBasic
from monkey.monkey import Monkey
from lanuchtest.lanuchapp import LanuchApp
from Installtest.installapp import InstallApp
from logintest.logintest import LoginApp
from report.client import get_html
from config import *
def kill_pid(port):
'''
结束appium进程
:return:
'''
if os.popen('lsof -i:{}'.format(port)).read() == '':
logger.info('未查询到进程')
else:
result = os.popen('lsof -i:{}'.format(gunicorn_port)).readlines()
for line in result:
if 'Python' in line or 'python2.7' in line:
pid = line.split()[1]
subprocess.call('kill -9 {}'.format(pid),shell=True)
logger.info('kill进程{}'.format(pid))
def start_gunicorn():
os.chdir(report)
kill_pid(gunicorn_port)
cmd = 'gunicorn -D -w 1 -b {} server:app'.format(gunicorn_address)
subprocess.call(cmd, shell=True)
time.sleep(3)
logger.info('启动gunicorn服务!')
def make_env():
if os.path.exists(android_tmp):
shutil.rmtree(android_tmp)
logger.info('删除缓存目录:{}'.format(android_tmp))
os.makedirs(android_tmp)
logger.info('创建缓存目录:{}'.format(android_tmp))
def run(apk_path,device_name,runtime,mail_list):
make_env()
gb = GetBasic(apk_path,device_name)
lanuch_activity = gb.get_app_activity()
app_name = gb.get_app_name()
app_version = gb.get_app_version()
gb.get_all_activitys()
InstallApp(device_name,app_name,apk_path,install_app_log,uninstall_app_log).install_app()
LanuchApp(device_name,app_name,lanuch_activity,lanuch_app_log).lanuch_app()
LoginApp(device_name, app_name, lanuch_activity).test_login()
Monkey(device_name,runtime,app_name).start_monkey()
start_gunicorn()
get_html(apk_path,device_name,mail_list)
if __name__ == '__main__':
apk_path = sys.argv[1]
device_name = sys.argv[2]
run_time = sys.argv[3]
mail_list = sys.argv[4]
params = (apk_path + '\n' +
device_name + '\n' +
run_time + '\n' +
mail_list)
logger.info('参数:' + '\n' + '{}'.format(params))
run(apk_path,device_name,run_time,mail_list)