forked from yanchunhuo/AutomationTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_web_ui_test_report.py
143 lines (141 loc) · 9.21 KB
/
generate_web_ui_test_report.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#-*- coding:utf8 -*-
# 作者 yanchunhuo
# 创建时间 2018/01/19 22:36
from base.read_report_config import Read_Report_Config
from common.custom_multiprocessing import Custom_Pool
from common.network import Network
from common.strTool import StrTool
import platform
import subprocess
def generate_windows_reports(report_dir,port):
subprocess.check_output("start cmd.exe @cmd /c allure serve -p " + port + " " + report_dir, shell=True)
if __name__=='__main__':
report_config = Read_Report_Config().report_config
ieport=report_config.web_ui_ie_port
chromeport=report_config.web_ui_chrome_port
firefoxport=report_config.web_ui_firefox_port
if 'Windows' == platform.system():
# 初始化进程池
p_pool = Custom_Pool(3)
if ieport:
# 获得当前监听ie端口的进程id
get_ieport_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % ieport
try:
get_allure_process_id=subprocess.check_output(get_ieport_process_id_command, shell=True)
get_allure_process_id=get_allure_process_id.decode('utf-8')
get_allure_process_id=StrTool.getStringWithLBRB(get_allure_process_id, 'LISTENING', '\r\n').strip()
kill_allure_process_command='taskkill /F /pid %s'%get_allure_process_id
try:
subprocess.check_call(kill_allure_process_command,shell=True)
except:
print('关闭allure进程,进程id:' + get_allure_process_id + ',该进程监听已监听端口:' + ieport)
except:
print('allure未查找到监听端口%s的服务' % ieport)
print('生成ie报告,使用端口' + ieport)
print('ie报告地址:http://%s:%s/' % (Network.get_local_ip(), ieport))
p = p_pool.apply_async(generate_windows_reports,('output/web_ui/ie',ieport))
if chromeport:
# 获得当前监听chrome端口的进程id
get_chromeport_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % chromeport
try:
get_allure_process_id=subprocess.check_output(get_chromeport_process_id_command, shell=True)
get_allure_process_id=get_allure_process_id.decode('utf-8')
get_allure_process_id=StrTool.getStringWithLBRB(get_allure_process_id, 'LISTENING', '\r\n').strip()
kill_allure_process_command='taskkill /F /pid %s'%get_allure_process_id
try:
subprocess.check_call(kill_allure_process_command,shell=True)
except:
print('关闭allure进程,进程id:' + get_allure_process_id + ',该进程监听已监听端口:' + chromeport)
except:
print('allure未查找到监听端口%s的服务' % chromeport)
print('生成chrome报告,使用端口' + chromeport)
print('chrome报告地址:http://%s:%s/' % (Network.get_local_ip(), chromeport))
p = p_pool.apply_async(generate_windows_reports,('output/web_ui/chrome',chromeport))
if firefoxport:
# 获得当前监听ie端口的进程id
get_firefoxport_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % firefoxport
try:
get_allure_process_id=subprocess.check_output(get_firefoxport_process_id_command, shell=True)
get_allure_process_id=get_allure_process_id.decode('utf-8')
get_allure_process_id=StrTool.getStringWithLBRB(get_allure_process_id, 'LISTENING', '\r\n').strip()
kill_allure_process_command='taskkill /F /pid %s'%get_allure_process_id
try:
subprocess.check_call(kill_allure_process_command,shell=True)
except:
print('关闭allure进程,进程id:' + get_allure_process_id + ',该进程监听已监听端口:' + firefoxport)
except:
print('allure未查找到监听端口%s的服务' % firefoxport)
print('生成firefox报告,使用端口' + firefoxport)
print('firefox报告地址:http://%s:%s/' % (Network.get_local_ip(), firefoxport))
p = p_pool.apply_async(generate_windows_reports,('output/web_ui/firefox',firefoxport))
p_pool.close()
p_pool.join()
else:
# 获得当前allure所有进程id
get_allure_process_ids_command = "ps -ef|grep -i allure\\.CommandLine|grep -v grep|awk '{print $2}'"
allure_process_ids = subprocess.check_output(get_allure_process_ids_command, shell=True)
allure_process_ids = allure_process_ids.decode('utf-8')
allure_process_ids = allure_process_ids.split('\n')
if ieport:
# 获得当前监听ie端口的进程id
get_ieport_process_ids_command = "netstat -anp|grep -i "+ieport+"|grep -v grep|awk '{print $7}'|awk -F '/' '{print $1}'"
ieport_process_ids = subprocess.check_output(get_ieport_process_ids_command,shell=True)
ieport_process_ids = ieport_process_ids.decode('utf-8')
ieport_process_ids = ieport_process_ids.split('\n')
is_find = False
for ieport_process_id in ieport_process_ids:
if is_find:
break
for allure_process_id in allure_process_ids:
allure_process_id = allure_process_id.strip()
ieport_process_id = ieport_process_id.strip()
if allure_process_id == ieport_process_id and not is_find and allure_process_id and ieport_process_id:
print('关闭allure进程,进程id:' + allure_process_id.strip() + ',该进程监听已监听端口:' + ieport)
subprocess.check_output("kill -9 " + allure_process_id.strip(), shell=True)
is_find =True
break
print('生成ie报告,使用端口'+ieport)
print('ie报告地址:http://%s:%s/' % (Network.get_local_ip(), ieport))
subprocess.check_output("nohup allure serve -p " + ieport + " output/web_ui/ie >logs/ie_generate_web_ui_test_report.log 2>&1 &",shell=True)
if chromeport:
# 获得当前监听chrome端口的进程id
get_chromeport_process_ids_command = "netstat -anp|grep -i " + chromeport + "|grep -v grep|awk '{print $7}'|awk -F '/' '{print $1}'"
chromeport_process_ids = subprocess.check_output(get_chromeport_process_ids_command, shell=True)
chromeport_process_ids = chromeport_process_ids.decode('utf-8')
chromeport_process_ids = chromeport_process_ids.split('\n')
is_find = False
for chromeport_process_id in chromeport_process_ids:
if is_find:
break
for allure_process_id in allure_process_ids:
allure_process_id = allure_process_id.strip()
chromeport_process_id = chromeport_process_id.strip()
if allure_process_id == chromeport_process_id and not is_find and allure_process_id and chromeport_process_id:
print('关闭allure进程,进程id:' + allure_process_id.strip() + ',该进程监听已监听端口:' + chromeport)
subprocess.check_output("kill -9 " + allure_process_id.strip(), shell=True)
is_find = True
break
print('生成chrome报告,使用端口' + chromeport)
print('chromeport报告地址:http://%s:%s/' % (Network.get_local_ip(), chromeport))
subprocess.check_output("nohup allure serve -p " + chromeport + " output/web_ui/chrome >logs/chrome_generate_web_ui_test_report.log 2>&1 &",shell=True)
if firefoxport:
# 获得当前监听firefox端口的进程id
get_firefoxport_process_ids_command = "netstat -anp|grep -i " + firefoxport + "|grep -v grep|awk '{print $7}'|awk -F '/' '{print $1}'"
firefoxport_process_ids = subprocess.check_output(get_firefoxport_process_ids_command, shell=True)
firefoxport_process_ids = firefoxport_process_ids.decode('utf-8')
firefoxport_process_ids = firefoxport_process_ids.split('\n')
is_find = False
for firefoxport_process_id in firefoxport_process_ids:
if is_find:
break
for allure_process_id in allure_process_ids:
allure_process_id = allure_process_id.strip()
firefoxport_process_id = firefoxport_process_id.strip()
if allure_process_id == firefoxport_process_id and not is_find and allure_process_id and firefoxport_process_id:
print('关闭allure进程,进程id:'+allure_process_id.strip()+',该进程监听已监听端口:'+firefoxport)
subprocess.check_output("kill -9 " + allure_process_id, shell=True)
is_find = True
break
print('生成firefox报告,使用端口' + firefoxport)
print('firefoxport报告地址:http://%s:%s/' % (Network.get_local_ip(), firefoxport))
subprocess.check_output("nohup allure serve -p " + firefoxport + " output/web_ui/firefox >logs/firefox_generate_web_ui_test_report.log 2>&1 &",shell=True)