当前位置:网站首页>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 
边栏推荐
猜你喜欢
随机推荐
Digital triangle model acwing 1027 Grid access
STM32串口寄存器库函数配置方法
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
Summary of PMP learning materials
How to pass the PMP Exam in a short time?
面试题:高速PCB一般布局、布线原则
How long does the PMP usually need to prepare for the exam in advance?
Output all composite numbers between 6 and 1000
5A summary: seven stages of PMP learning
C language pointer (Part 1)
What is the value of getting a PMP certificate?
数字三角形模型 AcWing 1027. 方格取数
E-commerce campaign Guide
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
How does the project manager write the weekly summary and weekly plan?
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
硬件大熊原创合集(2022/06更新)
Simulation volume leetcode [general] 1706 Where does the ball meet
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾









