当前位置:网站首页>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
边栏推荐
- What is the use of PMP certificate?
- Several common database connection methods
- 硬件大熊原创合集(2022/06更新)
- Implement custom memory allocator
- 【ChaosBlade:节点磁盘填充、杀节点上指定进程、挂起节点上指定进程】
- STM32串口寄存器库函数配置方法
- [chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
- PMP Exam Preparation experience, seek common ground while reserving differences, and successfully pass the exam
- Leetcode question brushing record (array) combination sum, combination sum II
- 【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
猜你喜欢
Troublesome problem of image resizing when using typora to edit markdown to upload CSDN
Expérience de port série - simple réception et réception de données
UnityShader入门精要个人总结--基础篇(一)
PPT模板、素材下载网站(纯干货,建议收藏)
C language pointer (Part 2)
LED模拟与数字调光
STM32串口寄存器库函数配置方法
JVM 垃圾回收 详细学习笔记(二)
【istio简介、架构、组件】
Storage of data in memory
随机推荐
Several stages of PMP preparation study
Screen automatically generates database documents
go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
How can I apply for a PMP certificate?
What is the rating of Huishang futures company? Is it safe to open an account? I want to open an account, OK?
What is the use of PMP certificate?
What are the conditions for applying for NPDP?
Markdown编辑器Editor.md插件的使用
C language for calculating the product of two matrices
JVM 内存结构 详细学习笔记(一)
如何统计项目代码行数
Serial port experiment - simple data sending and receiving
9c09730c0eea36d495c3ff6efe3708d8
Troublesome problem of image resizing when using typora to edit markdown to upload CSDN
数据在内存中的存储
C language pointer (Part 2)
Unityshader introduction essentials personal summary -- Basic chapter (I)
Leetcode question brushing record (array) combination sum, combination sum II
Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up
Simulation volume leetcode [general] 1609 Parity tree