当前位置:网站首页>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
边栏推荐
- Isomorphic C language
- Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up
- 数据在内存中的存储
- LeetCode 715. Range 模块
- Original collection of hardware bear (updated on June 2022)
- The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
- OpenGL帧缓冲
- Ppt template and material download website (pure dry goods, recommended Collection)
- 9c09730c0eea36d495c3ff6efe3708d8
- UnityShader入门精要个人总结--基础篇(一)
猜你喜欢
Two schemes of unit test
LeetCode 736. LISP syntax parsing
How to use Arthas to view class variable values
Druid monitoring - Introduction to JMX usage and principle
Several stages of PMP preparation study
What are the conditions for applying for NPDP?
[istio introduction, architecture, components]
串口實驗——簡單數據收發
Systick滴答定时器
PMP Exam Preparation experience systematically improve project management knowledge through learning
随机推荐
外部中断实现按键实验
【ChaosBlade:节点磁盘填充、杀节点上指定进程、挂起节点上指定进程】
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
数据在内存中的存储
端口复用和重映像
Unityshader introduction essentials personal summary -- Basic chapter (I)
systemd
OpenGL三维图形绘制
MySQL master-slave delay solution
LeetCode 715. Range 模块
Unity shader beginner's Essentials (I) -- basic lighting notes
Hard core sharing: a common toolkit for hardware engineers
2022-07-06 unity core 9 - 3D animation
Reading notes of pyramid principle
模拟卷Leetcode【普通】1705. 吃苹果的最大数目
Simulation volume leetcode [general] 1705 The maximum number of apples to eat
Digital triangle model acwing 1027 Grid access
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
Original collection of hardware bear (updated on June 2022)
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop