当前位置:网站首页>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
边栏推荐
- Output a spiral matrix C language
- channel. Detailed explanation of queuedeclare parameters
- 模拟卷Leetcode【普通】1567. 乘积为正数的最长子数组长度
- Several stages of PMP preparation study
- Several common database connection methods
- Three updates to build applications for different types of devices | 2022 i/o key review
- 年薪50w阿里P8亲自下场,教你如何从测试进阶
- Reflections on the way of enterprise IT architecture transformation (Alibaba's China Taiwan strategic thought and architecture practice)
- Several methods of calculating the average value of two numbers
- RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
猜你喜欢
LeetCode 736. LISP syntax parsing
NVIC中断优先级管理
Calf problem
LeetCode 715. Range 模块
How to realize sliding operation component in fast application
外部中断实现按键实验
E-commerce campaign Guide
LeetCode 736. Lisp 语法解析
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
Interview question: general layout and wiring principles of high-speed PCB
随机推荐
C language pointer (Part 2)
2021 year end summary
JVM garbage collection detailed learning notes (II)
UnityShader入门精要个人总结--基础篇(一)
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
模拟卷Leetcode【普通】1706. 球会落何处
Cmake command line use
Ppt template and material download website (pure dry goods, recommended Collection)
How to count the number of project code lines
Druid monitoring - Introduction to JMX usage and principle
GoLand set goproxy
ChaosBlade:混沌工程简介(一)
Summary of PMP learning materials
MySQL master-slave delay solution
Newly found yii2 excel processing plug-in
Two schemes of unit test
PMP Exam Preparation experience, seek common ground while reserving differences, and successfully pass the exam
cmake命令行使用
Hard core sharing: a common toolkit for hardware engineers
PMP certificate preparation experience sharing