htmltestrunner自动化测试报告中,请问下怎么设置只显示当前用例的执行结果?

2021-03-02 10:57发布

[图]

2条回答
Anonyem
2楼 · 2021-03-03 09:18


fromtkinterimport*

fromseleniumimportwebdriver

importtkinterastk

fromtkinterimportscrolledtext,messagebox

fromtimeimportsleep

fromtkinterimportttk

importxlrd

importrequests

importjson

importqrcode

importunittest

importos

importtime

importHTMLTestRunner





classYongli(unittest.TestCase):


deftest_001(self):

print("执行用例test_001成功")

deftest_002(self):

print("执行用例test_002成功")

deftest_003(self):

print("执行用例test_003成功")

deftest_004(self):

print("执行用例test_004成功")

deftest_005(self):

print("执行用例test_005成功")

deftest_006(self):

print("执行用例test_006成功")

deftest_007(self):

print("执行用例test_007成功")

deftest_008(self):

print("执行用例test_008成功")

deftest_009(self):

print("执行用例test_009成功")

deftest_010(self):

print("执行用例test_010成功")

deftest_011(self):

print("执行用例test_011成功")

deftest_012(self):

print("执行用例test_012成功")

deftest_013(self):

print("执行用例test_013成功")

defquanxuan():

num=listb.size()#返回当前listbox总个数

listb.selection_set(0,num)#全部选中

defquxiao():

num=listb.size()#返回当前listbox总个数

listb.selection_clear(0,num)#取消所有选中


defbutton1():

suite=unittest.TestSuite()

num=listb.size()

result=[]

foriinrange(0,num):

iflistb.selection_includes(i)==True:

result.append(listb.get(i))

forjinresult:

suite.addTest(Yongli(j))

#unittest.TextTestRunner().run(suite)#此行要放在循环外面

now=time.strftime("%Y-%m-%d%H-%M-%S")

filename="E:\\python-jiaoben\\baogao\\"+now+".html"

fp=open(filename,"wb+")

runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title="用例集合",description="用例执行情况:")

runner.run(suite)

fp.close()

listba.insert(END,now)

defbutton2():

num001=listba.size()

foriinrange(0,num001):

iflistba.selection_includes(i)==True:

driver=webdriver.Chrome()

driver.get('E:\\python-jiaoben\\baogao\\%s.html'%listba.get(i))

defjiemian_info():

ws=jiemian.winfo_screenwidth()

hs=jiemian.winfo_screenheight()

x=(ws/2)-200

y=(hs/2)-200

print("%d,%d"%(ws,hs))

returnx,y

jiemian=Tk()

jiemian.title("自动化用例集合")

a,b=jiemian_info()

jiemian.geometry("600x400+%d+%d"%(a,b))

label=Label(jiemian,text='选择自动化用例')

label.grid(row=1,column=3,stick=W+E,pady=5)

labela=Label(jiemian,text='测试报告')

labela.grid(row=1,column=5,stick=W+E,pady=5)


listb=Listbox(jiemian,width=60,height=41,selectmode=MULTIPLE)

listb.grid(row=2,column=3,sticky=E+W,padx=10,pady=5,ipady=100,ipadx=80)

yscrollbar=tk.Scrollbar(listb,command=listb.yview)

yscrollbar.pack(side=tk.RIGHT,fill=tk.Y)

listb.config(yscrollcommand=yscrollbar.set)

listba=Listbox(jiemian,width=60,height=41)#多选标志:selectmode=MULTIPLE

listba.grid(row=2,column=5,sticky=E+W,padx=180,pady=5,ipady=100,ipadx=80)

yscrollbar=tk.Scrollbar(listba,command=listb.yview)

yscrollbar.pack(side=tk.RIGHT,fill=tk.Y)

listba.config(yscrollcommand=yscrollbar.set)

li=['test_001','test_002','test_003','test_004','test_005','test_006','test_007','test_008','test_009',\

'test_010','test_011','test_012','test_013']


defgetfilename(path):

"""根据路径获取特定格式的文件"""

file=os.listdir(path)

#print(file)

foriinfile:

#print(os.path.splitext(i))

ifos.path.splitext(i)[1]==".py":

print(i.replace('.py',''))

li.append(i.replace('.py',''))

baogao=[]

defhtmlbg(path):

file=os.listdir(path)

#print(file)

foriinfile:

#print(os.path.splitext(i))

ifos.path.splitext(i)[1]==".html":

print(i.replace('.html',''))

baogao.append(i.replace('.html',''))

getfilename('E:\python-jiaoben')

htmlbg('E:\\python-jiaoben\\baogao')

foriteminli:

listb.insert(END,item)

foritemainbaogao:

listba.insert(END,itema)

Button(jiemian,text="执行",width=8,command=button1).place(x=230,y=140)#,command=self.button1.grid(row=1,column=0,stick=W+E,padx=30)

Button(jiemian,text="全选",width=8,command=quanxuan).place(x=230,y=80)

Button(jiemian,text="取消",width=8,command=quxiao).place(x=300,y=80)

Button(jiemian,text="打开报告",width=8,command=button2).place(x=300,y=140)


jiemian.mainloop()

效果展示图


 

 


天使的奶爸
3楼 · 2021-03-06 11:38

importxlrd

importrequests

importjson

importqrcode

importunittest

importos

importtime

importHTMLTestRunner





classYongli(unittest.TestCase):


deftest_001(self):

print("执行用例test_001成功")

deftest_002(self):

print("执行用例test_002成功")

deftest_003(self):