Talking about postman setting token dependency steps

Foreword:

When postman is doing interface testing, most of the interfaces must have a token to run. We can obtain the token and set an environment variable for use by all interfaces in the same collection. Generally, the token value is obtained by calling the login interface 

Practical project: jeecg boot project

Project official website: http://www.jeecg.com

Interface 1: login interface

Interface 2: The home page obtains the IP access of the last week

Postman gets the token and sets the token dependency steps:

1. Create a test environment

 

2. Create two interfaces

3. Login to get token

{
    "username":"admin",
    "password":"123456",
    "remember_me":"true",
    "captcha":"j04j",
    "checkKey":"9169ea44fee2e773df644053d67c94a1"
}
// 参数分别为
// 用户名
// 密码
// 是否自动登录 
// 验证码
// 验证码ID

 

4. Save the obtained token to the test environment

var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", data.result.token);
// data为获取到的返回数据,token为我创建环境时的变量名

 

as the picture shows:

5. Interface 2: send request with token

interface parameter

Token naming: X-Access-Token 
Token reference: { {token}} 
Note: Double braces can refer to variables of the test environment

 

The request returns the token parameter successfully

In postman, after setting token dependencies for all interfaces, you need to save all project interfaces to collections, so that the interface test cases can be executed sequentially, so that the tokens in the project interfaces can be updated in real time, so that there is no token expiration Case.

Finally, I would like to thank everyone who has read my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, you can take it away if you need it:

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey, and I hope it can help you! Partners can click the small card below to receive   

Guess you like

Origin blog.csdn.net/hlsxjh/article/details/131903553