Interface testing entry artifact - Requests

origin

As we all know, automated testing is a topic that software testing enthusiasts have explored all their lives. In my opinion, as long as you do a good job of interface testing, your automated testing is at least half successful.

At the request of some enthusiastic readers, today I will learn about the basic usage of the python interface testing library-Requests and practice it, hoping to help you quickly get started with interface testing.

text

What are Requests?

Simply put, Requests is a python library that encapsulates http/https requests.

How to install Requests?

Easier, pip Dafa is good:

pip install requests

How to use Requests?

get request sample code

import requests

test = requests.get('http://www.baidu.com')

print(test)

console output

<Response [200]>



Process finished with exit code 0

Congratulations, we successfully sent the first get request to the Baidu homepage. The return value of requests.get is a Response object, and it can be clearly seen that the returned status code is 200 .

post request sample code

This time let's simulate a post request with parameters.

import requests


test = requests.post(url='http://47.106.10.19:5098/api/login',

                     json={'username': 'test', 'password': 'test'}).text

print(test)

console output

{

  ''''

  省略

  ''''

  "status": "ok"

}


Process finished with exit code 0

The requested address is the login interface of the test platform experience address , and the requested parameters are data in json format, including the correct account number and password.

After taking the text attribute of the returned Response object , you can clearly see that the status in the data returned by the interface is ok , which means the login is successful.

Summarize

After going through this article, I believe that everyone has a basic understanding of the Requests library, and we will see you in the next issue for more exciting content.

If the article is helpful to you, remember to like, bookmark, and add attention. I will share some dry goods from time to time...

END Supporting Learning Resources Sharing

Finally:  In order to give back to the die-hard fans, I have compiled a complete software testing video learning tutorial for you. If you need it, you can get it for free 【保证100%免费】

Software Testing Interview Documentation

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Ali, Tencent, and Byte, and some Byte bosses have given authoritative answers. Finish this set The interview materials believe that everyone can find a satisfactory job.

insert image description here

How to obtain the full set of information:

 

Guess you like

Origin blog.csdn.net/IT_LanTian/article/details/131229753