Three methods for Postman debugging that depend on the login interface

In interface testing, we often encounter some interfaces that can only be accessed after logging in. When we use Postman to debug such interfaces, there are generally three methods: 1. Request in turn
if
there is a document for the login interface, or it is easier to capture through packet capture To get the parameters and format of the login request, you can use Postman to request the login interface first, then the cookies will be stored locally (you can view them through the Postman Cookies manager), and then send the login-dependent interface, as shown in the figure:

Since Postman is generally used as a debugging interface, it is not very troublesome to request in sequence

2. Grab Cookies, bypass login (commonly used)
If you don’t have a login interface document and don’t bother to capture packets and analyze the login interface, you can log in directly on the browser, visit any page to grab cookies, and add them to dependent login in Postman In the header of the interface (note: there is no s in the cookie, the corresponding value can be pasted directly, without dividing into several lines), as shown in the figure:

3. Use the Pre-request Script script to send a login request before requesting
If Postman is used as an interface automation testing tool, we can send a login request in the pre-request script to make the request have a login status, as shown in the figure:

Form class Post request script:

// 构造一个Post x-www-form-urlencoded格式请求
const loginRequest = {
    url: 'http://115.28.108.130:5000/api/user/login/',
    method: "POST",
    body: {
        mode: 'urlencoded',
        urlencoded: 'name=张三&password=123456'
    }
};
//发送请求
pm.sendRequest(loginRequest, function (err, res) {
    console.log(err ? err : res.text());
});

Practical case

Optical theory is useless, you have to learn to follow along, and you have to do it yourself, so that you can apply what you have learned to practice. At this time, you can learn from some actual combat cases.

If it is helpful to you, please like and collect it to give the author an encouragement. It is also convenient for you to quickly find it next time.

If you don’t understand, please consult the small card below. The blogger also hopes to learn and progress with like-minded testers

At the right age, choose the right position, and try to give full play to your own advantages.

My road of automated test development is inseparable from the plan of each stage along the way, because I like planning and summarizing,

Test and develop video tutorials, study notes and receive portals! ! !
 

Guess you like

Origin blog.csdn.net/m0_59868866/article/details/130734150