we can use Jmeter do interface testing, but personally feel that there is a little limitation, with python is much more flexible,
Can be based on their own ideas to build more flexible, below to introduce a simple interface test example.
First we need to figure out our whole idea:
-
prepare our test data first, i.e. post data (the Get method can also send request data)
-
then we give the specified URL Send Request (post method)
3 Get The result data of Repones,
-
determine if the repones results meet the expected data
Here is the data we want to request via The Post method
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/94/E9/wKioL1kP4l2TduW6AAA6-5EmMtA515.png-wh_500x0-wm_ 3-wmp_4-s_2581445914.png "title=" post data. png "alt=" wkiol1kp4l2tduw6aaa6-5emmta515.png-wh_50 "/>
Headers to declare the type first, and then send the data request to the URL through the Requests.post method .
we get the content of the response message through the text method, and get the status code of the response via Stauts_code.
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/94/E9/wKioL1kP4mqgXG56AAAMDjEev3M702.png-wh_500x0-wm_ 3-wmp_4-s_3175243602.png "title=" gets the message. png "alt=" wkiol1kp4mqgxg56aaamdjeev3m702.png-wh_50 "/>
code to determine whether it is a zero, there is a representation and the server session is normal
The content of the message is judged to verify that it contains the expected data
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/94/E9/wKioL1kP4nTS-umuAAAQ7U47OwM024.png-wh_500x0-wm_ 3-wmp_4-s_1875097288.png "title=" judgment message. png "alt=" wkiol1kp4nts-umuaaaq7u47owm024.png-wh_50 "/>
The result is OK and can be registered successfully
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M00/94/E9/wKiom1kP4oOwjiOMAABJXa9XNm0594.png-wh_500x0-wm_ 3-wmp_4-s_787958860.png "title=" registered successfully. png "alt=" wkiom1kp4oowjiomaabjxa9xnm0594.png-wh_50 "/>
OK, here we have a simple interface test example is finished.
This article is from the "It Bug" blog, so be sure to keep this source http://laomomo.blog.51cto.com/6595318/1923112
Python---A simple interface test instance