当前位置:网站首页>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 
边栏推荐
- Leetcode刷题记录(数组)组合总和、组合总和 II
- JVM 垃圾回收 详细学习笔记(二)
- 硬核分享:硬件工程师常用工具包
- C语言指针(上篇)
- Simulation volume leetcode [general] 1567 Length of the longest subarray whose product is a positive number
- 串口实验——简单数据收发
- Reading notes of pyramid principle
- The essence of high availability
- Serial port experiment - simple data sending and receiving
- Isomorphic C language
猜你喜欢

2022-06-30 unity core 8 - model import

JVM 垃圾回收 详细学习笔记(二)

Druid monitoring - Introduction to JMX usage and principle

Esp32-ulp coprocessor low power mode RTC GPIO interrupt wake up

Common short chain design methods

JVM garbage collection detailed learning notes (II)

LeetCode 715. Range 模块

E-commerce campaign Guide

Ppt template and material download website (pure dry goods, recommended Collection)

LeetCode 736. LISP syntax parsing
随机推荐
H3C vxlan configuration
Selenium automation integration, eight years of testing experience, soft test engineer, an article to teach you
C language for calculating the product of two matrices
个人力扣题目分类记录
硬件大熊原创合集(2022/06更新)
2022-06-30 Unity核心8——模型导入
UnityShader入门精要个人总结--基础篇(一)
Summary of PMP learning materials
Screen automatically generates database documents
Systick tick timer
Upgrade Alibaba cloud RDS (relational database service) instance to com mysql. jdbc. exceptions. Troubleshooting of jdbc4.communicationsexception
Druid monitoring - Introduction to JMX usage and principle
寄存器地址名映射
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
Register address name mapping
[chaosblade: node CPU load, node network delay, node network packet loss, node domain name access exception]
How does the project manager write the weekly summary and weekly plan?
Newly found yii2 excel processing plug-in
阿里p8手把手教你,自动化测试应该如何实现多线程?赶紧码住
串口實驗——簡單數據收發