Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Requests, a starter tool for interface testing

Shulou Source: shulou.com Published: 2022-06-01 02:57:24 09月29日 Update

Interface testing entry tool Requests how to use, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Origin

As we all know, automated testing is a lifelong research topic for software testing enthusiasts. In my opinion, as long as the interface test is done well, your automated test will be at least half successful.

At the request of some enthusiastic readers, I will join you today to understand and practice the basic usage of the python interface test library-Requests.

What is Requests in the text?

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

How do I install Requests?

To put it more simply, the pip method 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

Process finished with exit code 0

Congratulations, we successfully issued the first get request to Baidu home page. The return value of requests.get is a Response object. You can clearly see 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 {

''

Omit

''

"status": "ok"

}

Process finished with exit code 0

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

After taking the text attribute on the returned Response object, you can clearly see that the status in the data returned by the API is ok, that is, the login is successful.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Test interface success code parameters address object console data examples help control login automation output tools clear passionate well-known representative Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Redmi Shulou Technology NVidia Shulou Tech Info