1、GUI界面
2、主要涉及界面的事件绑定
"""
V1.0、测试框架界面类的实现
(1)绑定事件的处理,另外根据输入的文件路径过长,将文本框拉长处理:调整比例且对box1做平铺
(2)事件处理中打开配置文件,并且对文件进行了读取
"""
import csv
import wx
class UI_testframe:
def __init__(self):
self.app = wx.App()
self.window = wx.Frame(None, title="测试框架v1.0", size=(400, 300))
self.panel = wx.Panel(self.window)
self.lbl_file=wx.StaticText(self.panel, label="测试框架配置文件")
self.txt_file=wx.TextCtrl(self.panel)
self.but_open=wx.Button(self.panel, label="打开")
self.but_run = wx.Button(self.panel, label="执行")
self.but_clear = wx.Button(self.panel, label="重置")
self.but_exit = wx.Button(self.panel, label="退出")
self.configfile = ""
def UI_layout(self):
box1 = wx.BoxSizer()
box1.Add(self.lbl_file, flag=wx.ALL, border=10),
box1.Add(self.txt_file, flag=wx.ALL, border=10, proportion=2),
box2 = wx.BoxSizer()
box2.Add(self.but_open, flag=wx.ALL, border=10),
box2.Add(self.but_run, flag=wx.ALL, border=10),
box2.Add(self.but_clear, flag=wx.ALL, border=10),
box2.Add(self.but_exit, flag=wx.ALL, border=10),
box3 = wx.BoxSizer(wx.VERTICAL)
box3.Add(box1, flag=wx.TOP | wx.EXPAND, border=40),
box3.Add(box2, flag=wx.TOP, border=40),
self.panel.SetSizer(box3)
def UI_event(self):
self.but_open.Bind(wx.EVT_BUTTON, self.openfile)
def openfile(self, event):
self.dlg_open = wx.FileDialog(self.panel, style=wx.FD_OPEN, message="打开文件", wildcard="*.csv")
if self.dlg_open.ShowModal()==wx.ID_OK:
self.txt_file.AppendText(self.dlg_open.GetPath())
self.configfile = self.dlg_open.GetPath()
def readfile(self):
file = open(self.configfile, "r", encoding="utf-8")
table = csv.reader(file)
for content in table:
print(content)
def UI_show(self):
self.window.Show()
self.app.MainLoop()
if __name__ == '__main__':
a = UI_testframe()
a.UI_layout()
a.UI_event()
a.UI_show()
"""
V1.1、测试框架界面类的实现
(1)新增了测试驱动类,用于测试驱动的执行
"""
import csv
import os
import wx
class UI_testframe:
def __init__(self):
self.app = wx.App()
self.window = wx.Frame(None, title="测试框架v1.0", size=(400, 300))
self.panel = wx.Panel(self.window)
self.lbl_file=wx.StaticText(self.panel, label="测试框架配置文件")
self.txt_file=wx.TextCtrl(self.panel)
self.but_open=wx.Button(self.panel, label="打开")
self.but_run = wx.Button(self.panel, label="执行")
self.but_clear = wx.Button(self.panel, label="重置")
self.but_exit = wx.Button(self.panel, label="退出")
self.configfile = ""
def UI_layout(self):
box1 = wx.BoxSizer()
box1.Add(self.lbl_file, flag=wx.ALL, border=10),
box1.Add(self.txt_file, flag=wx.ALL, border=10, proportion=2),
box2 = wx.BoxSizer()
box2.Add(self.but_open, flag=wx.ALL, border=10),
box2.Add(self.but_run, flag=wx.ALL, border=10),
box2.Add(self.but_clear, flag=wx.ALL, border=10),
box2.Add(self.but_exit, flag=wx.ALL, border=10),
box3 = wx.BoxSizer(wx.VERTICAL)
box3.Add(box1, flag=wx.TOP | wx.EXPAND, border=40),
box3.Add(box2, flag=wx.TOP, border=40),
self.panel.SetSizer(box3)
def UI_event(self):
self.but_open.Bind(wx.EVT_BUTTON, self.openfile)
self.but_run.Bind(wx.EVT_BUTTON, self.rundriver)
def openfile(self, event):
self.dlg_open = wx.FileDialog(self.panel, style=wx.FD_OPEN, message="打开文件", wildcard="*.csv")
if self.dlg_open.ShowModal()==wx.ID_OK:
self.txt_file.AppendText(self.dlg_open.GetPath())
self.configfile = self.dlg_open.GetPath()
def rundriver(self, event):
driver = DriverTestframe()
driver.runtestfile(self.configfile)
def UI_show(self):
self.window.Show()
self.app.MainLoop()
class DriverTestframe:
def runtestfile(self, file):
file = open(file, "r", encoding="utf-8")
table = csv.reader(file)
header = next(table)
for content in table:
configf = content[1]
os.system(f"python {configf}")
if __name__ == '__main__':
a = UI_testframe()
a.UI_layout()
a.UI_event()
a.UI_show()