当前位置:网站首页>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
边栏推荐
- [istio introduction, architecture, components]
- Chaosblade: introduction to chaos Engineering (I)
- Several methods of calculating the average value of two numbers
- Several stages of PMP preparation study
- JVM garbage collection detailed learning notes (II)
- go mod module declares its path as: gtihub. com/xxx-xx but was required as:xx-xx
- 面试题:高速PCB一般布局、布线原则
- Panel display technology: LCD and OLED
- RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
- NVIC中断优先级管理
猜你喜欢
面板显示技术:LCD与OLED
H3C VXLAN配置
Calf problem
STM32串口寄存器库函数配置方法
Platformization, a fulcrum of strong chain complementing chain
STM32 clock system
Markdown编辑器Editor.md插件的使用
Troublesome problem of image resizing when using typora to edit markdown to upload CSDN
Panel display technology: LCD and OLED
Common short chain design methods
随机推荐
LeetCode 715. Range module
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
Simulation volume leetcode [general] 1567 Length of the longest subarray whose product is a positive number
Reading notes of pyramid principle
模拟卷Leetcode【普通】1609. 奇偶树
Isomorphic C language
Three updates to build applications for different types of devices | 2022 i/o key review
2020 year end summary
Troublesome problem of image resizing when using typora to edit markdown to upload CSDN
Original collection of hardware bear (updated on May 2022)
[chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
JVM garbage collection detailed learning notes (II)
面试题:高速PCB一般布局、布线原则
Original collection of hardware bear (updated on June 2022)
[istio introduction, architecture, components]
Full link voltage test of the e-commerce campaign Guide
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
Interview question: general layout and wiring principles of high-speed PCB
寄存器地址名映射