Commit 0146e982 by zhangchunyao

code update 201909111051

parent 85f961b1
...@@ -16,7 +16,7 @@ reader.open_excle('/opt/apitest/apiAutoByJenkins/repot/apitest.xls') # for serv ...@@ -16,7 +16,7 @@ reader.open_excle('/opt/apitest/apiAutoByJenkins/repot/apitest.xls') # for serv
sheetname = reader.get_sheets() sheetname = reader.get_sheets()
# copy用例文件 # copy用例文件
# writer.copy_open('D:/workSpace/Python_workspace/apitest2.0.xls', 'D:/workSpace/Python_workspace/apitest2.0_1.xls') # for local # writer.copy_open('D:/workSpace/Python_workspace/apitest2.0.xls', 'D:/workSpace/Python_workspace/apitest2.0_1.xls') # for local
writer.copy_open('/opt/apitest/apiAutoByJenkins/repot/apitest.xls', '/opt/apitest/apiAutoByJenkins/repot/apitest1.xls') # for server writer.copy_open('/opt/apitest/apiAutoByJenkins/repot/caseForJenkins/apitest.xls', '/opt/apitest/apiAutoByJenkins/repot/caseForJenkins/apitest1.xls') # for server
sheetname1 = writer.get_sheets() sheetname1 = writer.get_sheets()
writer.set_sheet(sheetname1[0]) writer.set_sheet(sheetname1[0])
for sheet in sheetname: for sheet in sheetname:
...@@ -32,13 +32,15 @@ class Run(unittest.TestCase): ...@@ -32,13 +32,15 @@ class Run(unittest.TestCase):
def runner(self,line,http): def runner(self,line,http):
d = { d = {
"Post": [line[4], line[5], line[6], line[7], line[8]], "Post": [line[4], line[5], line[6], line[7], line[8]],
"Addheader": [line[4]], "Addheader": [line[4],line[5]],
"savejson": [line[4], line[5]], "savejson": [line[4], line[5]],
"clear_values": [], "clear_values": [],
"Url": [line[4]], "Url": [line[4]],
"Addjson": [line[4], line[5]], "Addjson": [line[4], line[5]],
"Database_query": [line[4], line[5], line[6]], "Database_query": [line[4], line[5], line[6]],
"Get": [line[4], line[5], line[6], line[7], line[8]] "Get": [line[4], line[5], line[6], line[7], line[8]],
"Parameter":[line[4]],
"Time":[line[4]]
} }
if len(line[0])>0 or len(line[1])>0: if len(line[0])>0 or len(line[1])>0:
return return
...@@ -46,12 +48,14 @@ class Run(unittest.TestCase): ...@@ -46,12 +48,14 @@ class Run(unittest.TestCase):
func = getattr(http, line[3]) func = getattr(http, line[3])
for k, v in d.items(): for k, v in d.items():
if line[3] in k: if line[3] in k:
print(v)
result = func(*v) result = func(*v)
return result return result
@ddt.data(*data) @ddt.data(*data)
def test_run(self,data): def test_run(self,data):
# 用例执行 # 用例执行
excle_value = reader.readline_new(data[-1]) excle_value = reader.readline_new(data[-1])
print(excle_value)
result = self.runner(excle_value, http) result = self.runner(excle_value, http)
if result != None: if result != None:
if isinstance(result, tuple): if isinstance(result, tuple):
...@@ -79,10 +83,12 @@ class Run(unittest.TestCase): ...@@ -79,10 +83,12 @@ class Run(unittest.TestCase):
writer.write(data[-1], 9, 'pass') writer.write(data[-1], 9, 'pass')
writer.write(data[-1], 10, results) writer.write(data[-1], 10, results)
#writer.save_close() #writer.save_close()
def tearDown(self): def tearDown(self):
# 保存文件 # 保存文件
writer.save_close() writer.save_close()
if __name__ == '__main__': if __name__ == '__main__':
run = Run() run = Run()
run.test_run() run.test_run()
\ No newline at end of file
...@@ -16,7 +16,7 @@ reader.open_excle('/opt/apitest/apiAutoByJenkins/repot/testcase.xls') # for ser ...@@ -16,7 +16,7 @@ reader.open_excle('/opt/apitest/apiAutoByJenkins/repot/testcase.xls') # for ser
sheetname = reader.get_sheets() sheetname = reader.get_sheets()
# copy用例文件 # copy用例文件
# writer.copy_open('D:/workSpace/Python_workspace/testcase2.0.xls', 'D:/workSpace/Python_workspace/testcase2.0_1.xls') # for local # writer.copy_open('D:/workSpace/Python_workspace/testcase2.0.xls', 'D:/workSpace/Python_workspace/testcase2.0_1.xls') # for local
writer.copy_open('/opt/apitest/apiAutoByJenkins/repot/testcase.xls', '/opt/apitest/apiAutoByJenkins/repot/testcase1.xls') # for server writer.copy_open('/opt/apitest/apiAutoByJenkins/repot/caseForJenkins/testcase.xls', '/opt/apitest/apiAutoByJenkins/repot/caseForJenkins/testcase1.xls') # for server
sheetname1 = writer.get_sheets() sheetname1 = writer.get_sheets()
writer.set_sheet(sheetname1[0]) writer.set_sheet(sheetname1[0])
for sheet in sheetname: for sheet in sheetname:
...@@ -38,7 +38,8 @@ class Run(unittest.TestCase): ...@@ -38,7 +38,8 @@ class Run(unittest.TestCase):
"Url": [line[4]], "Url": [line[4]],
"Addjson": [line[4], line[5]], "Addjson": [line[4], line[5]],
"Database_query": [line[4], line[5], line[6]], "Database_query": [line[4], line[5], line[6]],
"Get": [line[4], line[5], line[6], line[7], line[8]] "Get": [line[4], line[5], line[6], line[7], line[8]],
"Parameter":[line[4]]
} }
if len(line[0])>0 or len(line[1])>0: if len(line[0])>0 or len(line[1])>0:
return return
......
...@@ -9,26 +9,33 @@ qaTeamWebhook = 'https://oapi.dingtalk.com/robot/send?access_token=2656a52b44f1e ...@@ -9,26 +9,33 @@ qaTeamWebhook = 'https://oapi.dingtalk.com/robot/send?access_token=2656a52b44f1e
qaTeamDing = DingtalkChatbot(qaTeamWebhook) qaTeamDing = DingtalkChatbot(qaTeamWebhook)
runTime = time.strftime('%Y-%m-%d %H:%M:%S') runTime = time.strftime('%Y-%m-%d %H:%M:%S')
# 钉钉推送消息异常
def resultTextFalse(reporturl): def resultTextFalse(reporturl):
# 读取excel,获取到异常接口
# pathSingle = 'D:/workSpace/Python_workspace/apitest2.0_1.xls' # for local # pathSingle = 'D:/workSpace/Python_workspace/apitest2.0_1.xls' # for local
# pathMulti = 'D:/workSpace/Python_workspace/testcase2.0_1.xls' # for local # pathMulti = 'D:/workSpace/Python_workspace/testcase2.0_1.xls' # for local
pathSingle = '/opt/apitest/apiAutoByJenkins/repot/apitest1.xls' # for server pathSingle = '/opt/apitest/apiAutoByJenkins/repot/caseForJenkins/apitest1.xls' # for server
pathMulti = '/opt/apitest/apiAutoByJenkins/repot/testcase1.xls' #for server pathMulti = '/opt/apitest/apiAutoByJenkins/repot/caseForJenkins/testcase1.xls' #for server
# 判断文件是否存在
if (os.path.exists(pathSingle) or os.path.exists(pathMulti)): if (os.path.exists(pathSingle) or os.path.exists(pathMulti)):
readExp = Reader() readExp = Reader()
# 获取异常接口列表
arrExpSingle = readExp.api_result(pathSingle) arrExpSingle = readExp.api_result(pathSingle)
arrExpMulti = readExp.api_result(pathMulti) arrExpMulti = readExp.api_result(pathMulti)
# 处理钉钉推送信息格式
expSingleMsg = '\n'.join(arrExpSingle) expSingleMsg = '\n'.join(arrExpSingle)
expMultiMsg = '\n'.join(arrExpMulti) expMultiMsg = '\n'.join(arrExpMulti)
# 钉钉消息推送
qaTeamDing.send_text(msg = "接口自动化执行异常结果\n执行时间:"+ runTime+ "\n执行异常接口列表:\n"+expSingleMsg+"\n"+expMultiMsg+"\n详细结果地址:"+reporturl) qaTeamDing.send_text(msg = "接口自动化执行异常结果\n执行时间:"+ runTime+ "\n执行异常接口列表:\n"+expSingleMsg+"\n"+expMultiMsg+"\n详细结果地址:"+reporturl)
else : else :
print("resultFile is not exist,please check it") print("resultFile is not exist,please check it")
qaTeamDing.send_text(msg = "接口自动化执行异常结果\n执行时间:"+ runTime+ "\n详细结果地址:"+reporturl) qaTeamDing.send_text(msg = "接口自动化执行异常结果\n执行时间:"+ runTime+ "\n详细结果地址:"+reporturl)
# 钉钉推送正常消息,后期不推送
def resultTextPass(reporturl): def resultTextPass(reporturl):
qaTeamDing.send_text(msg = "接口自动化执行无误\n执行时间:"+ runTime+ "\n详细结果地址:"+reporturl) qaTeamDing.send_text(msg = "接口自动化执行无误\n执行时间:"+ runTime+ "\n详细结果地址:"+reporturl)
# 钉钉消息推送入口
def msgSend(passrate,reporturl): def msgSend(passrate,reporturl):
if float(passrate)==100.00: if float(passrate)==100.00:
resultTextPass(reporturl) resultTextPass(reporturl)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment