由于部分内容涉及公司机密,已用字母替换,不影响阅读
目前已兼容我们公司所有 app
response body 全字段验证(含字段类型)
字段变化导致 2 个大问题
尽量避免日常监控中跑接口对外网数据/用户的影响
配置文件
http接口测试框架配置信息
tester = tester
project = A
versionName = 2.2.2
versionCode = 237
host = a-webapi.test.b.com
getTokenHost = http://a-webapi.test.b.com/api/System/GetToken
loginHost = http://a-webapi.test.b.com/api/User/LoginV2
loginInfo = Phone=13750199962&Password=FGgIwe5oCdk%3D
SessionsPath = D:\Fiddler Sessions
ApiURL = http://apihelper.b.com/Home/API/c
# SpecialSessions >> 屏蔽的接口
SpecialSessions = ['GetToken', 'LoginV2', 'LogOut', 'BookingV2']
启动测试入口
"""
运行api测试总入口
"""
import sessions.Request
def launcher_api_test():
"""
1.获取接口列表
2.与本地sessions对比
3.差异化文件,是否继续
3.1否 继续录制接口
3.2是 开始跑接口
:return:
"""
r = sessions.Request.Request(0) # 0 >> A 1 >> B
r.start()
if __name__ == "__main__":
launcher_api_test()
头部、登录接口
def __get_token_header(self):
"""
生成token头部
:return:
"""
des = self.__get_token_des()
arr = (des, self.conf['systemType'], self.conf['Model'], self.conf['Release'], self.conf['DeviceId'],
self.conf['versionCode'], self.conf['versionName'], self.conf['AppBuild'], self.conf['DeviceOS'], "0")
authorization = self.AUTHORIZATION_TOKEN % arr
headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 'Authorization': authorization}
response = self.session.post(self.conf['getTokenHost'], headers=headers)
if json.loads(response.text)['StatsCode'] == 200:
data1 = json.loads(response.text)['Data']
self.time = data1['Time']
self.TOKEN_NAME = data1['TokenName']
self.TOKEN_VALUE = data1['TokenValue']
else:
print("GetToken失败,请手动检查")
utils.HandleJson.HandleJson.print_json(response.text)
def __login_session(self):
"""
调用登录接口,这样后面的接口都能正常访问了
:return:
"""
url_login = self.conf['loginHost']
headers = self.__get_session_header(url_login.split('api/')[-1])
data_login = r'%s' % self.conf['loginInfo']
response = self.session.post(url_login, headers=headers, data=data_login)
if json.loads(response.text)['StatsCode'] == 200:
data1 = json.loads(response.text)['Data']
self.uId = data1[self.head_uid]
self.uName = data1['NickName']
self.uPhone = data1['Phone']
self.SessionId = data1['Sid']
self.uType = data1['UserType']
self.uuid = data1['UID']
else:
print("登录失败,请手动检查")
utils.HandleJson.HandleJson.print_json(response.text)
接口片段
Request url: a-webapi.test.b.com/api/Circle/AddCancelCollectCircle
Request header: POST /api/Circle/AddCancelCollectCircle HTTP/1.1
Host: a-webapi.test.b.com
Accept: text/json
Authorization: Digest t="2016-08-04 16:41:19",SystemType="2",u="Circle/AddCancelCollectCircle",r="59e93eb1a6625adc6bff5ede5945a2f7",DeviceId="ffffffff-8416-49fe-3fdc-6ee400000000",Model="SM-N9100",DeviceOS="22",Release="5.1.1",VersionName="2.2.2",VersionCode="239",PushToken="",uId="3353",uName="123456ejz",uPhone="13750199962",SessionId="%2FZhckUf9%2Fd2soQZhYofjN021SdWUpLv0aW%2F3CJBr71vtOl1YHJda6J8p6P1hsQS0P3kqirm%2BtPs%3D",uType="1",bDChannelId="",bDUserId="",AppBuild="239",uUID="2255"
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 21
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/3.0.1
Request body: CircleId=6418&IsAdd=1
Response code: 200
Response body: {"StatsCode":200,"Message":"收藏成功","Data":null,"Other":null}
Session end
Request url: a-webapi.test.b.com/api/Circle/AddCancelCollectCircle
Request header: POST /api/Circle/AddCancelCollectCircle HTTP/1.1
Host: a-webapi.test.b.com
Accept: text/json
Authorization: Digest t="2016-08-04 16:41:22",SystemType="2",u="Circle/AddCancelCollectCircle",r="26dcb55ee9ac79995c21656517c455e8",DeviceId="ffffffff-8416-49fe-3fdc-6ee400000000",Model="SM-N9100",DeviceOS="22",Release="5.1.1",VersionName="2.2.2",VersionCode="239",PushToken="",uId="3353",uName="123456ejz",uPhone="13750199962",SessionId="%2FZhckUf9%2Fd2soQZhYofjN021SdWUpLv0aW%2F3CJBr71vtOl1YHJda6J8p6P1hsQS0P3kqirm%2BtPs%3D",uType="1",bDChannelId="",bDUserId="",AppBuild="239",uUID="2255"
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 21
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/3.0.1
Request body: CircleId=6418&IsAdd=0
Response code: 200
Response body: {"StatsCode":200,"Message":"取消收藏成功","Data":null,"Other":null}
Session end
接口列表
环境配置
token/session 替换
替换 fiddler js
fiddler js 自定义信息
//自定义参数设置
public static var filterUrl = "a-webapi.test.b.com";
public static var filePath = "D:\\Fiddler Sessions\\Api\\";
public static var filePathForRequested = "D:\\Fiddler Sessions\\Requested.txt";
public static var filePathForErrorResponse = "D:\\Fiddler Sessions\\ErrorResponse.txt";
public static var filePathForVerifyRequset = "D:\\Fiddler Sessions\\VerifyRequset.txt";
public static var filePathForRemoveSession = "D:\\Fiddler Sessions\\RemoveSession.txt";
public static var filePathForAddSession = "D:\\Fiddler Sessions\\AddSession.txt";