当前位置:网站首页>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
边栏推荐
- [NOIP2008 提高组] 笨小猴
- SQL injection vulnerability (MSSQL injection)
- 2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
- CADD course learning (8) -- virtual screening of Compound Library
- Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
- IPv6 comprehensive experiment
- RTP GB28181 文件测试工具
- acwing周赛58
- Uva1592 Database
- Luogu deep foundation part 1 Introduction to language Chapter 2 sequential structure programming
猜你喜欢
Programmers' position in the Internet industry | daily anecdotes
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
[FreeRTOS interrupt experiment]
Extension of graph theory
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
English Vocabulary - life scene memory method
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
Zynq learning notes (3) - partial reconfiguration
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
Digital children < daily question> (Digital DP)
随机推荐
Codeforces Round #804 (Div. 2)
几种RS485隔离通讯的方案介绍
Leetcode 186 Flip the word II in the string (2022.07.05)
Visio draws Tai Chi
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
RTP gb28181 document testing tool
【Try to Hack】john哈希破解工具
View workflow
acwing周赛58
Easyrecovery reliable and toll free data recovery computer software
The video in win10 computer system does not display thumbnails
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
我想问一下 按照现在mysql-cdc的设计,全量阶段,如果某一个chunk的binlog回填阶段,
SQL注入漏洞(MSSQL注入)
Knowledge consolidation source code implementation 3: buffer ringbuffer
The value of two date types is subtracted and converted to seconds
Platformio create libopencm3 + FreeRTOS project
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Selection of slow motion function
[lgr-109] Luogu may race II & windy round 6