优化了断言,新增统计,
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
2017-08-02 13:55:24,491 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:sasa, url:http://www.tuling123.com/openapi/api ,<2C><><EFBFBD><EFBFBD>:{'code': 40001, 'text': '<27>װ<EFBFBD><D7B0>ģ<EFBFBD>key<65><79><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6>'},Ԥ<><D4A4>:40002.0
|
||||
2017-08-02 13:55:43,601 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:, url:http://www.tuling123.com/openapi/api
|
||||
,<2C><><EFBFBD><EFBFBD>:{'code': 40002, 'text': '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵ʲô<CAB2><C3B4>?'},Ԥ<><D4A4>:40008.0
|
||||
@@ -1,3 +0,0 @@
|
||||
2017-08-02 13:57:16,412 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:sasa, url:http://www.tuling123.com/openapi/api ,<2C><><EFBFBD><EFBFBD>:{'code': 40001, 'text': '<27>װ<EFBFBD><D7B0>ģ<EFBFBD>key<65><79><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6>'},Ԥ<><D4A4>:40002.0
|
||||
2017-08-02 13:57:34,526 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:, url:http://www.tuling123.com/openapi/api
|
||||
,<2C><><EFBFBD><EFBFBD>:{'code': 40002, 'text': '<27>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD>ʲô<CAB2><C3B4><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>أ<EFBFBD>'},Ԥ<><D4A4>:40008.0
|
||||
@@ -1,3 +0,0 @@
|
||||
2017-08-02 13:59:55,634 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:sasa, url:http://www.tuling123.com/openapi/api ,<2C><><EFBFBD><EFBFBD>:{'code': 40001, 'text': '<27>װ<EFBFBD><D7B0>ģ<EFBFBD>key<65><79><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6>'},Ԥ<><D4A4>:40002.0
|
||||
2017-08-02 14:00:13,824 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:, url:http://www.tuling123.com/openapi/api
|
||||
,<2C><><EFBFBD><EFBFBD>:{'code': 40002, 'text': '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵ʲô<CAB2><C3B4>?'},Ԥ<><D4A4>:40008.0
|
||||
@@ -1,3 +0,0 @@
|
||||
2017-08-02 14:04:01,572 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:sasa, url:http://www.tuling123.com/openapi/api ,<2C><><EFBFBD><EFBFBD>:{'code': 40001, 'text': '<27>װ<EFBFBD><D7B0>ģ<EFBFBD>key<65><79><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6>'},Ԥ<><D4A4>:40002.0
|
||||
2017-08-02 14:04:19,782 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:, url:http://www.tuling123.com/openapi/api
|
||||
,<2C><><EFBFBD><EFBFBD>:{'code': 40002, 'text': '<27><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʤ<EFBFBD><CAA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'},Ԥ<><D4A4>:40008.0
|
||||
@@ -1,3 +0,0 @@
|
||||
2017-08-02 14:05:35,679 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:sasa, url:http://www.tuling123.com/openapi/api ,<2C><><EFBFBD><EFBFBD>:{'code': 40001, 'text': '<27>װ<EFBFBD><D7B0>ģ<EFBFBD>key<65><79><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6>'},Ԥ<><D4A4>:40002.0
|
||||
2017-08-02 14:05:53,789 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:, url:http://www.tuling123.com/openapi/api
|
||||
,<2C><><EFBFBD><EFBFBD>:{'code': 40002, 'text': '<27>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD>ʲô<CAB2><C3B4><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>أ<EFBFBD>'},Ԥ<><D4A4>:40008.0
|
||||
3
201708031258.log
Normal file
3
201708031258.log
Normal file
@@ -0,0 +1,3 @@
|
||||
2017-08-03 12:58:42,228 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:sasa, url:http://www.tuling123.com/openapi/api ,<2C><><EFBFBD><EFBFBD>:{'code': 40001, 'text': '<27>װ<EFBFBD><D7B0>ģ<EFBFBD>key<65><79><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6>'},Ԥ<><D4A4>:code=40001
|
||||
2017-08-03 12:59:00,326 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:, url:http://www.tuling123.com/openapi/api
|
||||
,<2C><><EFBFBD><EFBFBD>:{'code': 40002, 'text': '<27><>ʲô<CAB2><C3B4>˵<EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFA3AC><EFBFBD><EFBFBD>ֱ<EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD>Ŷ~'},Ԥ<><D4A4>:code=40002
|
||||
13
Public/create_report.py
Normal file
13
Public/create_report.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# encoding: utf-8
|
||||
"""
|
||||
@author: lileilei
|
||||
@file: create_report.py
|
||||
@time: 2017/8/3 12:27
|
||||
"""
|
||||
def save_result(testtime,toial,passnum,fail):
|
||||
try:
|
||||
f=open('result.txt','a')
|
||||
f.write("%s=%s=%s=%s \n"%(testtime,toial,passnum,fail))
|
||||
f.close()
|
||||
except:
|
||||
print('记录测试结果失败')
|
||||
@@ -29,4 +29,4 @@ def sendemali(filepath): #发送email
|
||||
server.login(from_addr, password)
|
||||
server.sendmail(from_addr, mail_to, msg.as_string())
|
||||
server.quit()
|
||||
print("邮件发送成功")
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2017/6/4 20:35
|
||||
# @Author : lileilei
|
||||
# @Site :
|
||||
# @File : get_excel.py
|
||||
# @Software: PyCharm
|
||||
import xlrd,xlwt
|
||||
|
||||
15
Public/panduan.py
Normal file
15
Public/panduan.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Date : 2017-08-02 21:54:08
|
||||
# @Author : lileilei
|
||||
def assert_in(asserqiwang,fanhuijson):
|
||||
if len(asserqiwang.split('=')) > 1:
|
||||
data = asserqiwang.split('&')
|
||||
result = dict([(item.split('=')) for item in data])
|
||||
value1=([(int(fanhuijson[key])) for key in result.keys()])
|
||||
value2=([(int(value)) for value in result.values()])
|
||||
if value1==value2:
|
||||
return 'pass'
|
||||
else:
|
||||
return 'fail'
|
||||
else:
|
||||
raise ('请填写期望值')
|
||||
@@ -86,10 +86,10 @@ def relust(titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuq
|
||||
if type(name) ==list:
|
||||
relus=' '
|
||||
for i in range(len(name)):
|
||||
relus+=(ceshixiangqing(id[i],name[i],key[i],coneent[i],url[i],meth[i],int(yuqi[i]),json[i],relust[i]))
|
||||
relus+=(ceshixiangqing(id[i],name[i],key[i],coneent[i],url[i],meth[i],yuqi[i],json[i],relust[i]))
|
||||
text=title(titles)+connent+time(starttime,endtime,passge,fail)+shanghai+relus+weibu
|
||||
else:
|
||||
text=title(titles)+connent+time(starttime,endtime,passge,fail)+shanghai+ceshixiangqing(id,name,key,coneent,url,meth,int(yuqi),json,relust)+weibu
|
||||
text=title(titles)+connent+time(starttime,endtime,passge,fail)+shanghai+ceshixiangqing(id,name,key,coneent,url,meth,yuqi,json,relust)+weibu
|
||||
return text
|
||||
def createHtml(filepath,titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuqi,json,relusts):
|
||||
texts=relust(titles,starttime,endtime,passge,fail,id,name,key,coneent,url,meth,yuqi,json,relusts)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2017/6/17 15:56
|
||||
# @Author : lileilei
|
||||
# @Site :
|
||||
# @File : tsest_log.py
|
||||
# @Software: PyCharm
|
||||
import logging,time,os
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
2017-08-02 13:50:42,184 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:sasa, url:http://www.tuling123.com/openapi/api ,<2C><><EFBFBD><EFBFBD>:{'code': 40001, 'text': '<27>װ<EFBFBD><D7B0>ģ<EFBFBD>key<65><79><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6>'},Ԥ<><D4A4>:40002.0
|
||||
2017-08-02 13:51:00,284 - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ - INFO - inputdata> <20><><EFBFBD><EFBFBD>:, url:http://www.tuling123.com/openapi/api
|
||||
,<2C><><EFBFBD><EFBFBD>:{'code': 40002, 'text': '<27><>ɶѽ<C9B6><D1BD>'},Ԥ<><D4A4>:40008.0
|
||||
@@ -7,17 +7,21 @@
|
||||
@time: 2017/6/9 12:45
|
||||
"""
|
||||
from Public.pyreport_excel import create
|
||||
import unittest,os,threading,datetime
|
||||
import os,threading,datetime
|
||||
from testCase.test_case import testinterface
|
||||
from Public.emmail import sendemali
|
||||
from Public.get_excel import datacel
|
||||
from Public.create_report import save_result
|
||||
def start():
|
||||
starttime=datetime.datetime.now()
|
||||
m=datetime.datetime.now().strftime("%Y%m%d")
|
||||
basdir = os.path.abspath(os.path.dirname(__file__))
|
||||
listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname=datacel()
|
||||
listrelust,list_fail, list_pass, list_json =testinterface()
|
||||
filepath = os.path.join(basdir + '\\test_Report\\relult.xls')
|
||||
filepath = os.path.join(basdir + '\\test_Report\\%s-result.xls'%m)
|
||||
if os.path.exists(filepath) is False:
|
||||
os.system(r'touch %s' % filepath)
|
||||
save_result(starttime, len(listrelust), ((list_pass)), list_fail)
|
||||
create(filename=filepath,list_fail=list_fail, list_pass=list_pass, list_json=list_json, listurls=listurl,
|
||||
listkeys=listkey,listconeents=listconeent, listfangshis=listfangshi, listqiwangs=listqiwang,
|
||||
listids=listid, listrelust=listrelust, listnames=listname)
|
||||
|
||||
@@ -5,15 +5,18 @@ from testCase.test_case import testinterface
|
||||
from Public.py_Html import createHtml
|
||||
from Public.get_excel import datacel
|
||||
from Public.emmail import sendemali
|
||||
from Public.create_report import save_result
|
||||
import threading
|
||||
def stast():
|
||||
starttime=datetime.datetime.now()
|
||||
day= time.strftime("%Y%m%d%H%M", time.localtime(time.time()))
|
||||
basdir=os.path.abspath(os.path.dirname(__file__))
|
||||
listid, listkey, listconeent, listurl, listfangshi, listqiwang, listname = datacel()
|
||||
listrelust, list_fail, list_pass, list_json = testinterface()
|
||||
filepath =os.path.join(basdir+'\\test_Report\\relult.html')
|
||||
filepath =os.path.join(basdir+'\\test_Report\\%s-result.html'%day)
|
||||
if os.path.exists(filepath) is False:
|
||||
os.system(r'touch %s' % filepath)
|
||||
save_result(starttime,len(listrelust),((list_pass)),list_fail)
|
||||
endtime=datetime.datetime.now()
|
||||
createHtml(titles='接口测试报告',filepath=filepath,starttime=starttime,
|
||||
endtime=endtime,passge=list_pass,fail=list_fail,
|
||||
@@ -21,12 +24,10 @@ def stast():
|
||||
yuqi=listqiwang,json=list_json,relusts=listrelust)
|
||||
# sendemali(filepath)
|
||||
def tThread():
|
||||
st=datetime.datetime.now()
|
||||
m=threading.Thread(target=stast,args=())
|
||||
m.run()
|
||||
end=datetime.datetime.now()
|
||||
if __name__ == '__main__':
|
||||
stast()
|
||||
tThread()
|
||||
|
||||
|
||||
|
||||
|
||||
17
panduan.py
17
panduan.py
@@ -1,17 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Date : 2017-08-02 21:54:08
|
||||
# @Author : lileilei
|
||||
m={
|
||||
'key':'APIKEY',
|
||||
'info': '今天天气怎么样',
|
||||
'loc':'北京市中关村',
|
||||
'userid':'123456'
|
||||
}
|
||||
me='userid=123456&info=今天天气怎么样'
|
||||
if len(me.split('=')) > 1:
|
||||
data = me.split('&')
|
||||
result = dict([(item.split('=')) for item in data])
|
||||
value1=([(m[key]) for key in result.keys()])
|
||||
value2=([(value) for value in result.values()])
|
||||
if value1==value2:
|
||||
print('pass')
|
||||
10
result.txt
Normal file
10
result.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
记录测试时间,测试总数,pass数量,失败数量 用‘=’拼接
|
||||
|
||||
2017-08-03 12:43:24.910136=2=2=0
|
||||
2017-08-03 12:45:16.609525=2=2=0
|
||||
2017-08-03 12:47:27.536014=2=2=0
|
||||
2017-08-03 12:49:40.110597=2=2=0
|
||||
2017-08-03 12:52:38.698811=2=2=0
|
||||
2017-08-03 12:53:42.818479=2=2=0
|
||||
2017-08-03 12:54:46.685132=2=2=0
|
||||
2017-08-03 12:58:24.075566=2=2=0
|
||||
@@ -6,6 +6,7 @@ from Interface.testFengzhuang import TestApi
|
||||
from Public.get_excel import datacel
|
||||
from Public.tsest_log import log_re
|
||||
listid,listkey,listconeent,listurl,listfangshi,listqiwang,listname=datacel()
|
||||
from Public.panduan import assert_in
|
||||
title='测试日志'
|
||||
log_can=log_re(title)
|
||||
def testinterface():
|
||||
@@ -18,7 +19,8 @@ def testinterface():
|
||||
apicode=api.getcode()
|
||||
apijson=api.getJson()
|
||||
log_can.info_log('inputdata> 参数:%s, url:%s ,返回:%s,预期:%s'%(listconeent[i],listurl[i],apijson,listqiwang[i]))
|
||||
if apicode==int(listqiwang[i]):
|
||||
assert_re=assert_in(asserqiwang=listqiwang[i],fanhuijson=apijson)
|
||||
if assert_re=='pass':
|
||||
list_json.append(apijson)
|
||||
listrelust.append('pass')
|
||||
list_pass += 1
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -11,12 +11,12 @@
|
||||
|
||||
<div style='width: 1170px;margin-left: 15%'>
|
||||
<h1>接口测试的结果</h1>
|
||||
<p><strong>开始时间:</strong> 2017-08-02 13:50:24.016425</p>
|
||||
<p><strong>结束时间:</strong> 2017-08-02 13:51:00.284499</p>
|
||||
<p><strong>耗时:</strong> 0:00:36.268074</p>
|
||||
<p><strong>开始时间:</strong> 2017-08-03 12:58:24.075566</p>
|
||||
<p><strong>结束时间:</strong> 2017-08-03 12:59:00.367642</p>
|
||||
<p><strong>耗时:</strong> 0:00:36.292076</p>
|
||||
<p><strong>结果:</strong>
|
||||
<span >Pass: <strong >0</strong>
|
||||
Fail: <strong >2</strong>
|
||||
<span >Pass: <strong >2</strong>
|
||||
Fail: <strong >0</strong>
|
||||
</span></p>
|
||||
<p ><strong>测试详情如下</strong></p> </div>
|
||||
|
||||
@@ -44,9 +44,9 @@
|
||||
</td>
|
||||
<td>http://www.tuling123.com/openapi/api</td>
|
||||
<td>POST</td>
|
||||
<td>40002</td>
|
||||
<td>code=40001</td>
|
||||
<td>{'code': 40001, 'text': '亲爱的,key不对哦。'}</td>
|
||||
<td bgcolor="fail">fail</td>
|
||||
<td bgcolor="green">pass</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -60,9 +60,9 @@
|
||||
<td>http://www.tuling123.com/openapi/api
|
||||
</td>
|
||||
<td>POST</td>
|
||||
<td>40008</td>
|
||||
<td>{'code': 40002, 'text': '干啥呀?'}</td>
|
||||
<td bgcolor="fail">fail</td>
|
||||
<td>code=40002</td>
|
||||
<td>{'code': 40002, 'text': '有什么想说的话,不用藏在心里,可以直接告诉我哦~'}</td>
|
||||
<td bgcolor="green">pass</td>
|
||||
</tr>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user