https://testerhome.com/topics/5631
- Http Interface Test Framework (IDEA + implementation + Open source + possible dystocia)
- Http Interface Test framework questions and Answers
- Fiddler Save session (Request)
Description
Since part of the content involves company secrets, it has been replaced with letters, without affecting reading
Actual effect
- Verify that 1000 interfaces take an average of 6s (see machine Configuration and Speed)
- First put into use, immediately found 5 interface anomalies and the verification process less than 30s of time
The next step of the framework
Currently compatible with all our company apps
Response Body full field validation (with field type)
2 major problems caused by field changes
- from the original int (0/1) into the Boolean type
- The timestamp length is suddenly changed from 10 bits to 13 bits.
Try to avoid the influence of the external network data/user on the daily monitoring and running interface
- The current practice is to mask the relevant interface
- Current status
- The data ID that is created when the interface is run is changed, however, deleting the interface still calls the old ID to remove it, causing the data to be deleted.
- Improved
- Intercept the response body that created the data for ID
- Intercept Delete interface request body, pass in the ID of the previous intercept
Latest Frame Chart (red part not completed)
Part of the Code
Configuration file
HTTP interface Test Framework configuration informationTester=TesterProject=AVersionname=2.2.2Versioncode= 237host = a-webapi.test.b.com< Span class= "py" >gettokenhost = http://a-webapi.test.b.com/api/system/gettoken< Span class= "py" >loginhost = http://a-webapi.test.b.com/api/user/loginv2 logininfo = phone=13750199962&password=fggiwe5ocdk%3dsessionspath = d:\fiddler Sessions< Span class= "py" >apiurl = http://apihelper.b.com/home/api/c# Specialsessions >> Shielded interface specialsessions = [' GetToken ', ' LoginV2 ', ' LogOut ', ' BookingV2 ']
Start Test Portal
"" "Run API Test Total Entry" "import Sessions. Requestdef launcher_api_test (): "" "1. Get interface List 2. Compare with local sessions 3. diff file, whether continue 3.1 no continue recording interface 3.2 is the start Run interface: return: "" "r = Sessions. Request. Request (0) # 0 >> A 1 >> B r. Start () if __name__ == "__main__" Span class= "P" >: launcher_api_test ()
Header, Login interface
Def__get_token_header(Self):"" "Generate Token Header: 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%ArrHeaders={' Content-type ':' application/x-www-form-urlencoded; Charset=utf-8 ',' Authorization ':Authorization}Response=Self.Session.Post(Self.Conf[' Gettokenhost '],Headers=Headers)IfJson.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 failed, please check manually")Utils.Handlejson.Handlejson.Print_json(Response.Text)Def__login_session(Self):"" "calls the login interface so that the subsequent interface will be properly accessed: 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)IfJson.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.= data1[ ' UID ' else: print ( "Login failed, please check manually" ) utils. Handlejson. Handlejson. Print_json (response. Text)
Interface Fragment
Request url:a-webapi.test.b.com/api/circle/addcancelcollectcirclerequest header:post/api/circle/ Addcancelcollectcircle http/1.1host:a-webapi.test.b.comaccept:text/jsonauthorization: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=" ", 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-8content-length:21connection:keep-aliveaccept-encoding:gzipuser-agent:okhttp/3.0.1request Body: Circleid=6418&isadd=1response Code:200response body: {"Statscode": $, "Message": "Collection Succeeded", "Data": null, "other": Null}session endRequest URL:A-WEBAPI.TEST.B.COM/API/CIRCLE/ADDCANcelcollectcirclerequest header:post/api/circle/addcancelcollectcircle http/1.1host:a-webapi.test.b.comaccept: Text/jsonauthorization: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=" ", 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-8content-length:21connection:keep-aliveaccept-encoding:gzipuser-agent:okhttp/3.0.1request Body: Circleid=6418&isadd=0response Code:200response body: {"Statscode": $, "Message": "Cancel Collection succeeded", "Data": null, "other": Null}session End
Interface List
What you need to do.
Fiddler JS Custom Information
Custom parameter settingsPublicStaticVarFilterurl="A-webapi.test.b.com";PublicStaticVarFilePath="D:\\fiddler sessions\\api\\";PublicStaticVarfilepathforrequested="D:\\fiddler Sessions\\requested.txt";Publicstatic var filepathforerrorresponse = "D:\\fiddler sessions\\errorresponse.txt" ;static var filepathforverifyrequset = span class= "s2" > "D:\\fiddler sessions\\verifyrequset.txt" ;static var filepathforremovesession = span class= "s2" > "D:\\fiddler sessions\\removesession.txt" ;static var filepathforaddsession = "D:\\fiddler sessions\\addsession.txt"
- GitHub Pull Replacement Code
- Welcome to communicate together
GitHub
Frame Address
[Python Test framework] HTTP interface Test framework