当前位置:网站首页>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 
边栏推荐
- 【ChaosBlade:根据标签删除POD、Pod 域名访问异常场景、Pod 文件系统 I/O 故障场景】
- Serial port experiment - simple data sending and receiving
- GoLand set goproxy
- Markdown editor Use of MD plug-in
- PMP Exam details after the release of the new exam outline
- 【Istio Network CRD VirtualService、Envoyfilter】
- ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
- What is the value of getting a PMP certificate?
- Unity Shader入门精要初级篇(一)-- 基础光照笔记
- C language pointer (Part 1)
猜你喜欢
随机推荐
Vagrant failed to mount directory mount: unknown filesystem type 'vboxsf'
PMP examination experience sharing
JVM 垃圾回收 详细学习笔记(二)
Personal deduction topic classification record
Several methods of calculating the average value of two numbers
Several stages of PMP preparation study
How does the project manager write the weekly summary and weekly plan?
Hard core sharing: a common toolkit for hardware engineers
ChaosBlade:混沌工程简介(一)
LeetCode 736. Lisp 语法解析
How can I apply for a PMP certificate?
Unity Shader入门精要初级篇(一)-- 基础光照笔记
面试题:高速PCB一般布局、布线原则
[chaosblade: node disk filling, killing the specified process on the node, suspending the specified process on the node]
C语言指针(中篇)
Two schemes of unit test
2021 year end summary
LeetCode 715. Range module
阿里p8手把手教你,自动化测试应该如何实现多线程?赶紧码住
How to pass the PMP Exam in a short time?









