生活随笔
收集整理的這篇文章主要介紹了
风评接口测试
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
風(fēng)險(xiǎn)評(píng)測(cè)頁(yè)面的接口測(cè)試
一、手動(dòng)測(cè)試流程
1、登錄系統(tǒng)
2、答完8道題后點(diǎn)擊提交
二、接口測(cè)試:
返回的信息是嵌套的,調(diào)用接口一直返回200,數(shù)據(jù)并沒(méi)有發(fā)生更改
學(xué)習(xí)?Selenium的可關(guān)注下??解決動(dòng)態(tài)渲染頁(yè)面元素定位問(wèn)題
pc端的風(fēng)評(píng)頁(yè)面就屬于這類問(wèn)題
import requests
import json
import unittest
import HTMLTestRunnertelphone =18200717087
#參數(shù)化手機(jī)號(hào)碼(#67)
ur1=
'http://118.178.247.--:8081/systLogonUser/adminLogon.do'
headers = {
'Content-Type':
'application/x-www-form-urlencoded',
'Referer':
'118.178.247.67'}
data =
{'userName':telphone ,'pwd':
'123456Aa','verifyCode': 121
}
print(type(data))
r = requests.post(url=ur1,data=data,headers=
headers)
repones =
r.text
print(
'1',r.text)
print(
'2',r.status_code)
print(
'3',r.text[12:28
])'''
{"userOptions":[{"questionNo":"RISK0","userOption":"3"},{"questionNo":"RISK1","userOption":"3"},{"questionNo":"RISK2","userOption":"3"},{"questionNo":"RISK3","userOption":"3"},{"questionNo":"RISK4","userOption":"3"},{"questionNo":"RISK5","userOption":"3"},{"questionNo":"RISK6","userOption":"3"},{"questionNo":"RISK7","userOption":"3"}],"questionType":"RISK"}
{"userOptions":[{"questionNo":"RISK0","userOption":"3"},{"questionNo":"RISK1","userOption":"3"},{"questionNo":"RISK2","userOption":"3"},{"questionNo":"RISK3","userOption":"3"},{"questionNo":"RISK4","userOption":"3"},{"questionNo":"RISK5","userOption":"3"},{"questionNo":"RISK6","userOption":"3"},{"questionNo":"RISK7","userOption":"3"}],"questionType":"RISK"}
'''
url2=
'http://118.178.247.67:8081/question/list/present.do'
headers2 = {
'Content-Type':
'application/x-www-form-urlencoded',
'Referer':
'118.178.247.67'}
# jsonString={"userOptions":[{"questionNo":"RISK0","userOption":"3"},{"questionNo":"RISK1","userOption":"3"},{"questionNo":"RISK2","userOption":"3"},{"questionNo":"RISK3","userOption":"3"},{"questionNo":"RISK4","userOption":"3"},{"questionNo":"RISK5","userOption":"3"},{"questionNo":"RISK6","userOption":"3"},{"questionNo":"RISK7","userOption":"3"}],"questionType":"RISK"}
# print('class:dict:',type(jsonString))
jsonString1 = json.dumps({
"userOptions":[{
"questionNo":
"RISK0",
"userOption":
"0"},{"questionNo":
"RISK1",
"userOption":
"0"},{"questionNo":
"RISK2",
"userOption":
"0"},{"questionNo":
"RISK3",
"userOption":
"0"},{"questionNo":
"RISK4",
"userOption":
"0"},{"questionNo":
"RISK5",
"userOption":
"0"},{"questionNo":
"RISK6",
"userOption":
"0"},{"questionNo":
"RISK7",
"userOption":
"0"}],
"questionType":
"RISK"}, indent=4
)
print(
'輸出jsonString1:',jsonString1)
# userOptionslist=[{"questionNo":"RISK0","userOption":"0"},{"questionNo":"RISK1","userOption":"0"},{"questionNo":"RISK2","userOption":"0"},{"questionNo":"RISK3","userOption":"0"},{"questionNo":"RISK4","userOption":"0"},{"questionNo":"RISK5","userOption":"0"},{"questionNo":"RISK6","userOption":"0"},{"questionNo":"RISK7","userOption":"0"}]
# userOptionslist='[{"questionNo":"RISK0","userOption":"0"},{"questionNo":"RISK1","userOption":"0"},{"questionNo":"RISK2","userOption":"0"},{"questionNo":"RISK3","userOption":"0"},{"questionNo":"RISK4","userOption":"0"},{"questionNo":"RISK5","userOption":"0"},{"questionNo":"RISK6","userOption":"0"},{"questionNo":"RISK7","userOption":"0"}]'
data2 =
{
# 'jsonString':jsonString1,
# # "jsonString":{'userOptions':'{0}'.format(userOptionslist),'questionType':'RISK'},
# 'jsonString':'{"userOptions":[{"questionNo":"RISK0","userOption":"0"},{"questionNo":"RISK1","userOption":"0"},{"questionNo":"RISK2","userOption":"0"},{"questionNo":"RISK3","userOption":"0"},{"questionNo":"RISK4","userOption":"0"},{"questionNo":"RISK5","userOption":"0"},{"questionNo":"RISK6","userOption":"0"},{"questionNo":"RISK7","userOption":"0"}],"questionType":"RISK"}',# 'userOptions':userOptionslist,'jsonString':{
'userOptions':[{
"questionNo":
"RISK0",
"userOption":
"0"},{"questionNo":
"RISK1",
"userOption":
"0"},{"questionNo":
"RISK2",
"userOption":
"0"},{"questionNo":
"RISK3",
"userOption":
"0"},{"questionNo":
"RISK4",
"userOption":
"0"},{"questionNo":
"RISK5",
"userOption":
"0"},{"questionNo":
"RISK6",
"userOption":
"0"},{"questionNo":
"RISK7",
"userOption":
"0"}],
"questionType":
"RISK"},
# 'jsonString':{'userOptions':[{'questionNo':'RISK0','userOption':0},
# {'questionNo':'RISK1','userOption':0},
# {'questionNo':'RISK2','userOption':0},
# {'questionNo':'RISK3','userOption':0},
# {'questionNo':'RISK4','userOption':0},
# {'questionNo':'RISK5','userOption':0},
# {'questionNo':'RISK6','userOption':0},
# {'questionNo':'RISK7','userOption':0}],'questionType':'RISK'},
# 'jsonString':{'userOptions':[{'questionNo':'RISK0','userOption':0},
# {'questionNo':'RISK1','userOption':0},
# {'questionNo':'RISK2','userOption':0},
# {'questionNo':'RISK3','userOption':0},
# {'questionNo':'RISK4','userOption':0},
# {'questionNo':'RISK5','userOption':0},
# {'questionNo':'RISK6','userOption':0},
# {'questionNo':'RISK7','userOption':0}],'questionType':'RISK'},
# 'jsonString':{"userOptions":[{"questionNo":"RISK0","userOption":0},{"questionNo":"RISK1","userOption":0},{"questionNo":"RISK2","userOption":0},{"questionNo":"RISK3","userOption":0},{"questionNo":"RISK4","userOption":0},{"questionNo":"RISK5","userOption":0},{"questionNo":"RISK6","userOption":0},{"questionNo":"RISK7","userOption":0}],"questionType":"RISK"},
'_':
'1547535857821'
}
print(type(data2))
s=
requests.session()
r=s.get(url=url2,data=data2,headers=
headers2)
# r = requests.post(url=url2,data=data2,headers=headers2)
# r = requests.post(url2, data=jsonString)
repones =
r.text
print(
'11',repones)
print(
'22:',r.status_code)# url3='http://118.178.247.67:8081/personal/system/personal/safetyData.do'
# headers3 = {'Content-Type':'application/x-www-form-urlencoded','Referer':'118.178.247.67'}
# data3 = {
#
# }
# r = requests.post(url=url3,data=data3,headers=headers3)
# repones = r.text
# print('111',r.text)
# print('222',r.status_code) ?2019-05-06風(fēng)險(xiǎn)評(píng)測(cè)接口調(diào)不通的解決
原因:雖然登錄了但是沒(méi)有傳遞session,解決方法如下:
1_login.py
import thisimport requests
import json
import unittest
import HTMLTestRunneryuming=
'http://test-a.==''''登錄'''
s=
requests.session() #session的設(shè)置
def login(phone):headers54 = {
'Content-Type':
'application/x-www-form-urlencoded; charset=UTF-8','Accept':
'application/json, text/javascript, */*; q=0.01','Referer':
'{0}/systLogonUser/login.do'.format(yuming)}url54=
'{0}/systLogonUser/adminLogon.do'.format(yuming)data54 =
{'userName':phone,'pwd':
'123456Aa','verifyCode':121
}r=s.post(url=url54,data=data54,headers=
headers54)login_response=
r.textlogin_statuscode=
r.status_codeprint(login_statuscode, login_response, s)return login_statuscode,login_response,slogin(18200717108)
6_riskdo.py
import requests
import json
import unittest
import HTMLTestRunner'''風(fēng)險(xiǎn)評(píng)測(cè)'''f=
__import__(
'1_login')
f.login(18200717108
) #調(diào)用登錄模塊
def riskdo(phone):headers =
{'Accept':
'application/json, text/javascript, */*; q=0.01','Content-Type':
'application/x-www-form-urlencoded; charset=UTF-8','Referer':
'{0}/login.do'.format(f.yuming)}url =
'{0}/question/list/present.do'.format(f.yuming)data =
{'jsonString':
'{"userOptions":[{"questionNo":"RISK0","userOption":"0"},{"questionNo":"RISK1","userOption":"0"},{"questionNo":"RISK2","userOption":"0"},{"questionNo":"RISK3","userOption":"0"},{"questionNo":"RISK4","userOption":"0"},{"questionNo":"RISK5","userOption":"0"},{"questionNo":"RISK6","userOption":"0"},{"questionNo":"RISK7","userOption":"0"}],"questionType":"RISK"}','_':
'1556173375897'}r = f.s.post(url=url, data=data, headers=
headers)print(r.status_code)print(r.text)riskdo(18200717108)
至此,登錄,風(fēng)評(píng)、充值、連接oracle設(shè)置CA認(rèn)證都可以python接口實(shí)現(xiàn)了,開(kāi)戶的可以通過(guò)python+selenium實(shí)現(xiàn),但是瀏覽器似乎有時(shí)有問(wèn)題(安全插件的安裝)。。。
轉(zhuǎn)載于:https://www.cnblogs.com/jpr-ok/p/10330665.html
總結(jié)
以上是生活随笔為你收集整理的风评接口测试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。