Python????????????
??????????ι??? ???????[ 2017/2/28 10:45:32 ] ?????????????? Python
????????
????????????HTTPЭ??????????????????HTTP?????????????Python????????С?????????????requests?????????????????
???????
???????????????С????漰???????????????????????????????????
?????????????????????????????????????????????????????????????
?????????
?????????????????JSON?????棬????????????????Excel?????棬??JSON???????????JSON????????????????????Excel???Python??JSON????????????????????????????????
{
"TestId": "testcase004"??
"Method": "post"??
"Title": "???????????"??
"Desc": "???????????"??
"Url": "http://xxx.xxx.xxx.xx"??
"InputArg": {
"action": "44803"??
"account": "1865998xxxx"??
"uniqueid": "00D7C889-06A0-426E-BAB1-5741A1192038"??
"title": "???????"??
"summary": "??????"??
"message": "12345"??
"msgtype": "25"??
"menuid": "203"
}??
"Result": {
"errorno": "0"
}
}
?????????????????????????????????????????е?????
????????????
???????????????????requests??飬????JSON?ж????????????post??get????????????????????????棬???????????????????????????????txt???????????????????
f = file("case.json")
testData = json.load(f)
f.close()
def sendData(testData?? num):
payload = {}
# ??json?л?????????
for x in testData[num]['InputArg'].items():
payload[x[0]] = x[1]
with open('leftside.txt'?? 'a+') as f:
f.write(testData[num]['TestId'])
f.write('-')
f.write(testData[num]['Title'])
f.write('n')
# ????????
data = requests.get(testData[num]['Url']?? params=payload)
r = data.json()
???????????
????????????????????????????????????????????????????????δ洢????????????????洢????????????????洢??鷳???????txt???????洢???????ɡ?
with open('rightside.txt'?? 'a+') as rs:
rs.write('????????')
rs.write('|')
rs.write('????:'+testData[num]['Title'])
rs.write('|')
rs.write('??????:'+testData[num]['Method'])
rs.write('|')
rs.write('????????:'+testData[num]['Desc'])
rs.write('|')
rs.write('??????:'+testData[num]['Url'])
rs.write('|')
rs.write('???????:'+str(payload).decode("unicode-escape").encode("utf-8").replace("u'"??"'"))
rs.write('|')
rs.write(testData[num]['TestId'])
rs.write('n')
????????ж?
????????ж???????????????ж????????????????????????????????????????????д???????ж???
with open('result.txt'?? 'a+') as rst:
rst.write('????????')
rst.write('|')
for x?? y in r.items():
rst.write(' : '.join([x?? y]))
rst.write('|')
# д??????
try:
if cmp(r?? testData[num]['Result']) == 0:
rst.write('pass')
else:
rst.write('fail')
except Exception:
rst.write('no except result')
rst.write('n')
??????????????3?????????????????????????????????????????
??????????????
?????????????????????????????????????????????????????txt????洢???????????a+???????????y??????????????????????????
????????????????β???????????Python???txt????е????????????Django???????????????????????requests????????????????Report??????С?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11