ResString=HTTPInvoke(sInput,requesturi) #执行调用
print ResString
#获取返回码并比较
#printResString,checkitem
#如果服务器返回码不是200,直接报错。
ifResString.startswith('[Response_Code_err]'):
real_value=ResString
print real_value
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
#写测试结果
write_result(excelobj, suiteid, caseid, excelobj.resultCol, ret1)
continue
#判断是使用xml还是json解析。
if ResString.find('xmlversion=')>0:
try:
real_value=et.fromstring(ResString).find(checkitem).text
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
except:
printsInput+"返回不是标准的XML!"
real_value=sInput+"返回不是标准的XML!"
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
elifResString.startswith('{'):
try:
ResString=ToUnicode(ResString)
hjson =json.loads(ResString)
expstr=excelobj.read_data(suiteid,excelobj.casebegin+caseid, 13)
ifstr(checkitem).startswith('['):
try:
checkitem= checkitem.replace("‘","'")
checkitem= checkitem.replace("’","'")
hjson =json.loads(ResString)
precmd='hjson'+checkitem
real_value=eval(precmd)
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
except:
real_value=checkitem+'解析失败,请检查层级及语法!'
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
else :
ResString=ToUnicode(ResString)
#printResString
ifResString.find(checkitem)>0:
pattern = re.compile(r'%s(.*?),' % checkitem)
res = pattern.findall(ResString)
ifres==[]:#如果要匹配的字段在最后,则没有逗号,只能匹配大括号
pattern = re.compile(r'%s(.*?)}' % checkitem)
res =pattern.findall(ResString)
#printres[0]
else:
print'key:'+checkitem+'在response中不存在!'
real_value='key:'+checkitem+'在response中不存在!'
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
#写测试结果
write_result(excelobj, suiteid, caseid, excelobj.resultCol, ret1)
continue
real_value=res[0].replace('"','')
#printreal_value
real_value=real_value[1:]
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
except:
printsInput+"返回不是标准的json!"
real_value=sInput+"返回不是标准的json!"
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
else:#非json非xml文件
expstr=excelobj.read_data(suiteid,excelobj.casebegin+caseid, 14)
ifResString.find(expstr)>0:
real_value=expstr
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)
else:
print sInput+'中不存在'+expstr
real_value=sInput+'中不存在'+expstr
ret1=check_result(excelobj, suiteid, caseid,real_value,excelobj.CheckVaule)