Python---A simple interface test instance

Source: Internet
Author: User

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.

    • Our thinking is as follows:

First we need to figure out our whole idea:

    1. prepare our test data first, i.e. post data (the Get method can also send request data)

    2. then we give the specified URL Send Request (post method)

3 Get The result data of Repones,

    1. determine if the repones results meet the expected data

    • Let me give you an example of a registered VPN account:

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 .

    • after requesting the data we wait for the server to respond and get the Repones data

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 "/>

    • We make judgments about the messages we get, whether they contain the expected data

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 "/>

    • Run See results

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.