-
Notifications
You must be signed in to change notification settings - Fork 336
/
generate_web_ui_test_report.py
178 lines (175 loc) · 11.8 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#
# generate_web_ui_test_report.py
# @author yanchunhuo
# @description
# @github https://github.com/yanchunhuo
# @created 2021-04-13T10:59:18.033Z+08:00
# @last-modified 2023-03-27T18:20:43.976Z+08:00
#
from base.read_report_config import Read_Report_Config
from common.strTool import StrTool
from common.custom_multiprocessing import Custom_Pool
from common.dateTimeTool import DateTimeTool
from common.network import Network
import argparse
import platform
import subprocess
def generate_windows_reports(report_dir,test_time,port):
generate_report_command='allure generate %s/report_data -o %s/report/web_ui_report_%s'%(report_dir,report_dir,test_time)
subprocess.check_output(generate_report_command,shell=True)
open_report_command='start cmd.exe @cmd /c "allure open -p %s %s/report/web_ui_report_%s"'%(port,report_dir,test_time)
subprocess.check_output(open_report_command,shell=True)
if __name__=='__main__':
parser=argparse.ArgumentParser()
parser.add_argument('-ip', '--ie_port', help='ie生成报告使用的端口', type=str)
parser.add_argument('-cp', '--chrome_port', help='chrome生成报告使用的端口', type=str)
parser.add_argument('-fp', '--firefox_port', help='firefox生成报告使用的端口', type=str)
args=parser.parse_args()
report_config = Read_Report_Config().report_config
if args.ie_port:
ieport=args.ie_port
else:
ieport=report_config.web_ui_ie_port
if args.chrome_port:
chromeport=args.chrome_port
else:
chromeport=report_config.web_ui_chrome_port
if args.firefox_port:
firefoxport=args.firefox_port
else:
firefoxport=report_config.web_ui_firefox_port
test_time=DateTimeTool.getNowTime('%Y_%m_%d_%H_%M_%S_%f')
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('%s关闭allure进程,进程id:%s,该进程监听已监听端口:%s'%(DateTimeTool.getNowTime(),get_allure_process_id,ieport))
except:
print('%sallure未查找到监听端口%s的服务' % (DateTimeTool.getNowTime(),ieport))
print('%s生成ie报告,使用端口%s'%(DateTimeTool.getNowTime(),ieport))
print('%sie报告地址:http://%s:%s/' % (DateTimeTool.getNowTime(),Network.get_local_ip(), ieport))
p = p_pool.apply_async(generate_windows_reports,('output/web_ui/ie',test_time,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('%s关闭allure进程,进程id:%s,该进程监听已监听端口:%s'%(DateTimeTool.getNowTime(),get_allure_process_id,chromeport))
except:
print('%sallure未查找到监听端口%s的服务' % (DateTimeTool.getNowTime(),chromeport))
print('%s生成chrome报告,使用端口%s'%(DateTimeTool.getNowTime(),chromeport))
print('%schrome报告地址:http://%s:%s/' % (DateTimeTool.getNowTime(),Network.get_local_ip(), chromeport))
p = p_pool.apply_async(generate_windows_reports,('output/web_ui/chrome',test_time,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('%s关闭allure进程,进程id:%s,该进程监听已监听端口:%s'%(DateTimeTool.getNowTime(),get_allure_process_id,firefoxport))
except:
print('%sallure未查找到监听端口%s的服务' % (DateTimeTool.getNowTime(),firefoxport))
print('%s生成firefox报告,使用端口%s'%(DateTimeTool.getNowTime(),firefoxport))
print('%sfirefox报告地址:http://%s:%s/' % (DateTimeTool.getNowTime(),Network.get_local_ip(), firefoxport))
p = p_pool.apply_async(generate_windows_reports,('output/web_ui/firefox',test_time,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('%s关闭allure进程,进程id:%s,该进程监听已监听端口:%s'%(DateTimeTool.getNowTime(),allure_process_id.strip(),ieport))
subprocess.check_output("kill -9 " + allure_process_id.strip(), shell=True)
is_find =True
break
print('%s生成ie报告,使用端口%s'%(DateTimeTool.getNowTime(),ieport))
print('%sie报告地址:http://%s:%s/' % (DateTimeTool.getNowTime(),Network.get_local_ip(), ieport))
generate_report_command='allure generate output/web_ui/ie/report_data -o output/web_ui/ie/report/web_ui_report_%s'%(test_time)
subprocess.check_output(generate_report_command,shell=True)
open_report_command='nohup allure open -p %s output/web_ui/ie/report/web_ui_report_%s >logs/generate_web_ui_test_ie_report_%s.log 2>&1 &'%(ieport,test_time,test_time)
subprocess.check_output(open_report_command,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('%s关闭allure进程,进程id:%s,该进程监听已监听端口:%s'%(DateTimeTool.getNowTime(),allure_process_id.strip(),chromeport))
subprocess.check_output("kill -9 " + allure_process_id.strip(), shell=True)
is_find = True
break
print('%s生成chrome报告,使用端口%s'%(DateTimeTool.getNowTime(),chromeport))
print('%schromeport报告地址:http://%s:%s/' % (DateTimeTool.getNowTime(),Network.get_local_ip(), chromeport))
generate_report_command='allure generate output/web_ui/chrome/report_data -o output/web_ui/chrome/report/web_ui_report_%s'%(test_time)
subprocess.check_output(generate_report_command,shell=True)
open_report_command='nohup allure open -p %s output/web_ui/chrome/report/web_ui_report_%s >logs/generate_web_ui_test_chrome_report_%s.log 2>&1 &'%(chromeport,test_time,test_time)
subprocess.check_output(open_report_command,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('%s关闭allure进程,进程id:%s,该进程监听已监听端口:%s'%(DateTimeTool.getNowTime(),allure_process_id.strip(),firefoxport))
subprocess.check_output("kill -9 " + allure_process_id, shell=True)
is_find = True
break
print('%s生成firefox报告,使用端口%s'%(DateTimeTool.getNowTime(),firefoxport))
print('%sfirefoxport报告地址:http://%s:%s/' % (DateTimeTool.getNowTime(),Network.get_local_ip(), firefoxport))
generate_report_command='allure generate output/web_ui/firefox/report_data -o output/web_ui/firefox/report/web_ui_report_%s'%(test_time)
subprocess.check_output(generate_report_command,shell=True)
open_report_command='nohup allure open -p %s output/web_ui/firefox/report/web_ui_report_%s >logs/generate_web_ui_test_firefox_report_%s.log 2>&1 &'%(firefoxport,test_time,test_time)
subprocess.check_output(open_report_command,shell=True)