AutoFramework/Runner/API/DefaultRunnerGUI.py

155 lines
6.0 KiB
Python
Raw Normal View History

2022-08-31 03:12:45 +08:00
import os
import time
import threading
from Base.Class.GUI import *
from Base.Class.Command import *
_cl = (
'#202020',
'#e5e5e5',
'#9c9c9c'
)
_ft = (
'Microsoft Yahei',
9,
'bold'
)
_ct = []
_th = None
class _Thread(threading.Thread):
def __init__(self, function=None, *args, **kwargs):
super().__init__(*args, **kwargs)
if function:
self.run = function
self.start()
class _Window(Window):
@staticmethod
def open_testcase():
_ct[1].set(tkinter.filedialog.askopenfilename(
filetypes=[
(
'Excel 文件',
'*.xlsx'
)
]
))
@staticmethod
def save_report():
_ct[18].set(tkinter.filedialog.asksaveasfilename(
filetypes=[
(
'文本文档',
'*.html'
)
],
defaultextension='html',
initialfile='test'
))
@staticmethod
def save_log():
_ct[21].set(tkinter.filedialog.asksaveasfilename(
filetypes=[
(
'文本文档',
'*.log'
)
],
defaultextension='log',
initialfile='test'
))
if __name__ == '__main__':
def thread_func_monitor():
global _th
global _ct
try:
while True:
_ct[28].dis() if _th and _th.is_alive() else _ct[28].nor()
time.sleep(0.5)
except RuntimeError:
pass
def thread_func_runtest():
global _th
global _ct
opt_w = _ct[1].get()
opt_t = _ct[4].get()
opt_m = _ct[6].get()
opt_a = _ct[8].get()
opt_l = _ct[10].get()
opt_o = {'根据顺序执行': 1, '根据级别分类': 2}[_ct[12].get()]
opt_r = {'': 1, '': 0}[_ct[14].get()]
opt_v = int(_ct[16].get())
opt_p = _ct[18].get()
opt_x = _ct[21].get()
opt_i = _ct[24].get()
opt_d = _ct[26].get()
shell(cmd='%s \"%s\" -w \"%s\" -t \"%s\" -m \"%s\" -a \"%s\" -l \"%s\" -o \"%s\" -r \"%s\" -v \"%s\" -p \"%s\" -x \"%s\" -i \"%s\" -d \"%s\"' % (
sys.executable,
os.path.abspath(os.path.join(os.path.dirname(__file__), 'DefaultRunner.py')),
opt_w,
opt_t,
opt_m,
opt_a,
opt_l,
opt_o,
opt_r,
opt_v,
opt_p,
opt_x,
opt_i,
opt_d,
), stdout=sys.stdout, stderr=sys.stderr)
def _run_runtest():
global _th
if not _th or not _th.is_alive(): _th = _Thread(thread_func_runtest)
def _run_monitor():
_Thread(thread_func_monitor)
def _run_ui(window):
window.mainloop()
_root = _Window('接口自动化测试', w=572, h=450, bg=_cl[0])
2022-08-31 04:24:00 +08:00
_ct.append(_root.Labels(row=0, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='用例文件'))
2022-08-31 03:12:45 +08:00
_ct.append(_root.Entrys(row=0, col=1, font=_ft, bg=_cl[1], fg=_cl[2], w=54, readonly=True, text=''))
_ct.append(_root.Button(row=0, col=2, font=_ft, bg=_cl[0], fg=_cl[1], text='选择文件', function=_root.open_testcase))
_ct.append(_root.Labels(row=1, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='用例名称'))
_ct.append(_root.Entrys(row=1, col=1, font=_ft, bg=_cl[0], fg=_cl[1], w=54, text='测试用例'))
_ct.append(_root.Labels(row=2, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='模块名称'))
_ct.append(_root.Entrys(row=2, col=1, font=_ft, bg=_cl[0], fg=_cl[1], w=54, text=''))
_ct.append(_root.Labels(row=3, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='用例编号'))
_ct.append(_root.Entrys(row=3, col=1, font=_ft, bg=_cl[0], fg=_cl[1], w=54, text=''))
_ct.append(_root.Labels(row=4, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='用例级别'))
_ct.append(_root.Entrys(row=4, col=1, font=_ft, bg=_cl[0], fg=_cl[1], w=54, text='P0,P1,P2,P3'))
_ct.append(_root.Labels(row=5, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='用例组织模式'))
_ct.append(_root.Option(row=5, col=1, font=_ft, bg=_cl[1], fg=_cl[2], w=24, defaulti=0, data=['根据顺序执行', '根据级别分类']))
_ct.append(_root.Labels(row=6, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='写入测试结果'))
_ct.append(_root.Option(row=6, col=1, font=_ft, bg=_cl[1], fg=_cl[2], w=24, defaulti=1, data=['', ''])) #14
_ct.append(_root.Labels(row=7, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='日志和报告详细度'))
_ct.append(_root.Option(row=7, col=1, font=_ft, bg=_cl[1], fg=_cl[2], w=24, defaulti=1, data=[1, 2, 3, 4, 5])) # 16
_ct.append(_root.Labels(row=8, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='报告输出路径'))
_ct.append(_root.Entrys(row=8, col=1, font=_ft, bg=_cl[1], fg=_cl[2], w=54, readonly=True, text=''))
_ct.append(_root.Button(row=8, col=2, font=_ft, bg=_cl[0], fg=_cl[1], text='选择目录', function=_root.save_report))
2022-08-31 04:24:00 +08:00
_ct.append(_root.Labels(row=9, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='日志输出路径'))
2022-08-31 03:12:45 +08:00
_ct.append(_root.Entrys(row=9, col=1, font=_ft, bg=_cl[1], fg=_cl[2], w=54, readonly=True, text=''))
_ct.append(_root.Button(row=9, col=2, font=_ft, bg=_cl[0], fg=_cl[1], text='选择目录', function=_root.save_log))
_ct.append(_root.Labels(row=10, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='报告标题'))
_ct.append(_root.Entrys(row=10, col=1, font=_ft, bg=_cl[0], fg=_cl[1], w=54, text='自动化测试报告'))
_ct.append(_root.Labels(row=11, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='报告描述'))
_ct.append(_root.Entrys(row=11, col=1, font=_ft, bg=_cl[0], fg=_cl[1], w=54, text='暂无描述'))
_ct.append(_root.Labels(row=12, col=0, font=_ft, bg=_cl[0], fg=_cl[1], text='执行测试'))
_ct.append(_root.Button(row=12, col=1, font=_ft, bg=_cl[0], fg=_cl[1], w=32, text='立即运行', function=_run_runtest))
_run_monitor()
_run_ui(_root)