当前位置:网站首页>Postman pre script - global variables and environment variables
Postman pre script - global variables and environment variables
2022-07-06 04:47:00 【Cool leg hair!】
Global and environment variables
Global and environment variables
Global variables
Concept : stay Postman Globally effective variables , Globally unique .
Set up :
Code settings :
pm.globals.set(“ Global variable name ”, The value of the global variable )
// Example : pm.globals.set("glb_age", 100)
obtain :
Code acquisition :
var The variable that receives the value = pm.globals.get(“ Global variable name ”)
// Example : var ret = pm.globals.get("glb_age") // ret The value of is 100
Request parameter acquisition (postman Interface access ):
{ { Global variable name }}
// Example : { { glb_age}}
environment variable
Concept : stay Specific circumstances ( Production environment 、 development environment 、 Test environment ) Next , Variables in effect , Only in this environment .
Set up :
Code settings :
pm.environment.set(" Environment variable name ", Environment variable value )
// Example pm.environment.set("env_age", 99)
obtain :
Code acquisition :
var The variable that receives the value = pm.environment.get(" Environment variable name ")
// Example var ret = pm.environment.get("env_age") // ret The value of is 99
Request parameter acquisition (postman Interface access ):
{ { Environment variable name }}
// Example { { env_age}}
Postman Request pre script
- stay send When the button is clicked , Request pre script code , Be executed at the first time . stay postman Internal reality http Request before .
hypothesis , Such a scene :
When adjusting an interface , To input “ Time stamp ”, If you enter “ Time stamp ” The absolute value of , Beyond the standard time 10 minute . Call... Is not allowed .
Time stamp
- Time stamp : Corresponding to absolute time , from 1970 year 1 month 1 Japan 00:00:00 Up to now Seconds experienced .
One day :86400 second
51 year 6 month (180) 9 God — 1,624,665,600 second
Case study
Call Baidu homepage interface , Send timestamp to server
Implementation steps :
stay Pre-request Script On the tab , Add code . Get the time stamp , Write global variables
// Get the time stamp var timestamp = new Date().getTime() // Set the timestamp to Global variables pm.globals.set("glb_timestamp", timestamp)
Click on Send Button , Send a request . Execute before sending the request The above code . Write global variables
View the variables written
- stay Request parameters ( Interface ) in , Use global variables .{ { Global variable name }}
- stay postman Of Console , see Sent http request
working principle
边栏推荐
- Platformio create libopencm3 + FreeRTOS project
- Tengine kernel parameters
- 二叉树基本知识和例题
- Chip debugging of es8316 of imx8mp
- Codeforces Round #804 (Div. 2)
- Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
- ORM aggregate query and native database operation
- [mathematical modeling] differential equation -- sustainable development of fishing industry
- acwing周赛58
- 比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元
猜你喜欢
Flink kakfa data read and write to Hudi
Embedded development program framework
Basic explanation of turtle module - draw curve
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
ISP learning (2)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
acwing周赛58
随机推荐
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
Summary of three log knowledge points of MySQL
Visio draws Tai Chi
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
[Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
acwing周赛58
Ue5 small knowledge points to enable the setting of lumen
Project manager, can you draw prototypes? Does the project manager need to do product design?
newton interpolation
Postman关联
[HBZ share] reasons for slow addition and deletion of ArrayList and fast query
Programmers' position in the Internet industry | daily anecdotes
RTP GB28181 文件测试工具
Finance online homework
SQL injection vulnerability (MSSQL injection)
Extension of graph theory
NPM command -- install dependent packages -- Usage / explanation
Knowledge consolidation source code implementation 3: buffer ringbuffer
Fuzzy -- basic application method of AFL
Excellent PM must experience these three levels of transformation!