当前位置:网站首页>Postman interface test (II. Set global variables \ sets)
Postman interface test (II. Set global variables \ sets)
2022-07-07 09:08:00 【Song_ Lun】
Preface
use postman When doing interface tests We often encounter delivery token/Authorization And dynamic id The problem of , It is automatically generated after the user logs in token/Authorization After that, the next interface is written manually every time header Inside , This is actually quite troublesome .
Manually set variables
Be careful ! Variable references use { { value }}
, and jmeter equally .
Automatically get the value and fill it in dynamically
Pass on token
Log in successfully and get token And set it to variable
- First, in the test Add to determine whether the interface returns successfully .
// First, judge whether the interface login is successful or not 200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
- And then get token take token Set as variable
// obtain data The data in it (id,token etc. )
var data = JSON.parse(responseBody);
if (data.data.id) {
tests["Body has id"] = true;
postman.setEnvironmentVariable("id", data.data.id);
}
else {
tests["Body has token"] = false;
}
- Set the variable name in the variable , Value is empty ; Variable id With the following id Corresponding
Pass on Authorization
Authorization And token Dissimilarity It is placed in the header among
test Parameter write the following assertion judgment
// First, judge whether the interface login is successful or not 200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// obtain header Inside Authorization
var jsondata = postman.getResponseHeader("Authorization");
postman.setEnvironmentVariable("Authorization", jsondata);
console.log(jsondata)
Global interface usage
Pass on Data Next Tonkerh&id
Pass on Herder Next Authorization
Let's take a look at the effect
边栏推荐
猜你喜欢
Calf problem
数字三角形模型 AcWing 1027. 方格取数
E-commerce campaign Guide
JVM 垃圾回收 详细学习笔记(二)
[istio introduction, architecture, components]
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
平台化,强链补链的一个支点
PMP examination experience sharing
Systick滴答定时器
C language for calculating the product of two matrices
随机推荐
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
如何统计项目代码行数
OpenGL三维图形绘制
H3C vxlan configuration
C语言指针(上篇)
Platformization, a fulcrum of strong chain complementing chain
Common operating commands of Linux
LeetCode 715. Range 模块
With an annual salary of 50W, Alibaba P8 will come out in person to teach you how to advance from testing
Digital triangle model acwing 1027 Grid access
Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
The essence of high availability
OpenGL frame buffer
Implement custom memory allocator
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
LED模拟与数字调光
[chaosblade: delete pod according to the tag, pod domain name access exception scenario, pod file system i/o failure scenario]
Port occupation troubleshooting
Calculation s=1+12+123+1234+12345 C language
PMP experience learning and sharing process