#实现测试框架界面及驱动功能
import operator
import wx
import csv,os
#测试框架界面类
class UI_test_frame():
def __init__(self):
self.app=wx.App()
self.window=wx.Frame(None,title="测试框架",size=(400,300))
self.panel=wx.Panel(self.window)
#定义标签
self.filebq=wx.StaticText(self.panel,label="配置文件")
#定义文本框(设置只读)
self.filetxt=wx.TextCtrl(self.panel,style=wx.TE_READONLY)
#定义打开按钮
self.dakai=wx.Button(self.panel,label="打开")
#定义执行按钮
self.zhixing=wx.Button(self.panel,label="执行")
#定义重置按钮
self.chongzhi=wx.Button(self.panel,label="重置")
#定义退出按钮
self.tuichu= wx.Button(self.panel,label="退出")
def Box(self):
#设置一个水平的BoxSizer
boxsizer1=wx.BoxSizer()
boxsizer1.Add(self.filebq,proportion=2,flag=wx.ALL,border=10)
boxsizer1.Add(self.filetxt,proportion=6,flag=wx.ALL,border=10)
#设置第二个水平的BoxSizer
boxsizer2= wx.BoxSizer()
boxsizer2.Add(self.dakai,flag=wx.ALL,border=10)
boxsizer2.Add(self.zhixing,flag=wx.ALL,border=10)
boxsizer2.Add(self.chongzhi,flag=wx.ALL,border=10)
boxsizer2.Add(self.tuichu,flag=wx.ALL,border=10)
#设置垂直的BoxSizer
boxsizer3=wx.BoxSizer(wx.VERTICAL)
boxsizer3.Add(boxsizer1,flag=wx.TOP|wx.EXPAND,border=40)
boxsizer3.Add(boxsizer2)
#设置boxsizer生效
self.panel.SetSizer(boxsizer3)
def open_file(self,event):
#设置打开文件对话框
self.dlog=wx.FileDialog(self.panel,message="打开文件",wildcard="*.csv",style=wx.FD_OPEN)
#当点击确定,把文件信息放入文本框中
if self.dlog.ShowModal()==wx.ID_OK:
self.filetxt.AppendText(self.dlog.GetPath())
self.config=self.dlog.GetPath()
def run_driver(self,event):
#对文本框是否为空进行校验
filetxt=self.filetxt.GetValue()
if filetxt=="":
dlg=wx.MessageDialog(None,"请输入文件名和路径","提示信息",wx.YES_DEFAULT|wx.ICON_QUESTION)
if dlg.ShowModal()==wx.ID_YES:
dlg.Destroy()
else:
#调用测试驱动程序
driver_obj=driver()
driver_obj.runtest(self.config)
#重置
def clear(self,event):
self.filetxt.SetValue("")
#关闭窗体
def exit(self,event):
self.window.Close()
#将按钮和事件绑定
def event_bind(self):
self.dakai.Bind(wx.EVT_BUTTON, self.open_file)
self.zhixing.Bind(wx.EVT_BUTTON, self.run_driver)
self.chongzhi.Bind(wx.EVT_BUTTON,self.clear)
self.tuichu.Bind(wx.EVT_BUTTON, self.exit)
def run(self):
# 激活窗体
self.window.Show()
# 运行APP
self.app.MainLoop()
#测试框架驱动类
class driver():
#测试驱动执行方法
def runtest(self,config):
file=open(config,"r")
table=csv.reader(file)
#跳过首行
header=next(table)
list=[]
line=0
for row in table:
line+=1
dic={}
dic["num"]=int(row[3])
dic[row[1]] = row[2]
list.append(dic)
list1=sorted(list, key=operator.itemgetter("num"))
#print(list1)
for i in range(0,line):
n=0
for j in list1[i].items():
n+=1
if n==2:
path=j[0]
state=j[1]
if state=="yes":
strOS=("python "+path)
#执行文件
os.system(strOS)
if __name__ == '__main__':
UI_test_frame_obj=UI_test_frame()
UI_test_frame_obj.Box()
UI_test_frame_obj.event_bind()
UI_test_frame_obj.run()
配置文件: