动态变量 / 随机参数

# 动态变量 / 随机参数

动态变量是在接口运行中按指定规则生成的变量,100% 兼容 Postman 动态变量。

参数中使用动态变量的方式为{{变量名}},如{{$timestamp}}表示当前时间戳。

注意

  • 前置脚本和后置脚本需要通过 pm.variables.replaceIn()使用动态变量,如:

    var timestamp = pm.variables.replaceIn('{{$timestamp}}');
    
  • 当前实现的动态变量仅为了完全兼容 Postman,不支持中文;后续会考虑用 mock.js 的方式来实现动态变量,到时候会支持中文。

# 常用

变量名 说明 结果示例
$guid uuid-v4 格式的 guid "611c2e81-2ccb-42d8-9ddc-2d0bfa65c1b4"
"3a721b7f-7dc9-4c45-9777-516942b98e0d"
"22eca807-006b-47df-9511-e92e37f5071a"
$timestamp 以秒为单位的当前 UNIX 时间戳 1562757107, 1562757108, 1562757109
$isoTimestamp ISO 格式(zero UTC)当前时间戳 2019-10-21T06:05:50.000Z
2019-07-29T18:29:00.000Z
$randomUUID 随机 36 字符的 UUID "6929bb52-3ab2-448a-9796-d6480ecad36b"
"53151b27-034f-45a0-9f0a-d7b6075b67d0"
"727131a2-2717-44ad-ab02-006587e947dc"

# 文本、数字、颜色

变量名 说明 结果示例
$randomAlphaNumeric 单个随机字母/数字字符 6, "y", "z"
$randomBoolean 随机布尔值 (true/false) true, false, false, true
$randomInt 1 到 1000 之间的随机整数 802, 494, 200
$randomColor 随机颜色名 "red", "fuchsia", "grey"
$randomHexColor 随机 hex 格式颜色值 "#47594a", "#431e48", "#106f21"
$randomAbbreviation 一个随机的英文缩写 SQL, PCI, JSON

# 网络相关

变量名 说明 结果示例
$randomIP 随机 IPv4 地址 241.102.234.100, 216.7.27.38
$randomIPV6 随机 IPv6 地址 dbe2:7ae6:119b:c161:1560:6dda:3a9b:90a9
c482:23a4:ce4c:a668:7736:6cc5:b0b6:cc37
c791:18d1:fbba:87d8:d929:22aa:5a0a:ac3d
$randomMACAddress 随机 MAC 地址 33:d4:68:5f:b4:c7, 1f:6e:db:3d:ed:fa
$randomPassword 随机 15 位字母/数字字符组成的密码 t9iXe7COoDKv8k3, QAzNFQtvR9cg2rq
$randomLocale 随机 2 字符语言编码 (ISO 639-1) "ny", "sr", "si"
$randomUserAgent 随机浏览器 user agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.9.8; rv:15.6) Gecko/20100101 Firefox/15.6.6
Opera/10.27 (Windows NT 5.3; U; AB Presto/2.9.177 Version/10.00)
Mozilla/5.0 (Windows NT 6.2; rv:13.5) Gecko/20100101 Firefox/13.5.6
$randomProtocol 随机网络协议名 "http", "https"
$randomSemver 随机版本号 (semantic version 格式) 7.0.5, 2.5.8, 6.4.9

# 姓名

变量名 说明 结果示例
$randomFirstName 随机英文 first name Ethan, Chandler, Megane
$randomLastName 随机英文 last name Schaden, Schneider, Willms
$randomFullName 随机英文 first and last name Connie Runolfsdottir, Sylvan Fay, Jonathon Kunze
$randomNamePrefix 随机英文 name 前缀 Dr., Ms., Mr.
$randomNameSuffix 随机英文 name 后缀 I, MD, DDS

# 职业

变量名 说明 结果示例
$randomJobArea 随机英文职位领域 Mobility, Intranet, Configuration
$randomJobDescriptor 随机英文职位描述 Forward, Corporate, Senior
$randomJobTitle 随机英文职位名称 International Creative Liaison,
Product Factors Officer,
Future Interactions Executive
$randomJobType 随机英文类型 Supervisor, Manager, Coordinator

# 手机号,地址

变量名 说明 结果示例
$randomPhoneNumber 随机 10 位电话号码(国外) 700-008-5275, 494-261-3424, 662-302-7817
$randomPhoneNumberExt 随机 12 位电话号码(国外) 27-199-983-3864, 99-841-448-2775
$randomCity 随机城市名(国外) Spinkahaven, Korbinburgh, Lefflerport
$randomStreetName 随机街道名(国外) Kuhic Island, General Street, Kendrick Springs
$randomStreetAddress 随机住址(国外) 5742 Harvey Streets, 47906 Wilmer Orchard
$randomCountry 随机国家名称(英文) Lao People's Democratic Republic, Kazakhstan, Austria
$randomCountryCode 随机 2 字母的国家编码 (ISO 3166-1 alpha-2) CV, MD, TD
$randomLatitude 随机纬度 55.2099, 27.3644, -84.7514
$randomLongitude 随机经度 40.6609, 171.7139, -159.9757

# 图片

变量名 说明 结果示例
$randomImage 随机图片 http://lorempixel.com/640/480/technics
http://lorempixel.com/640/480/food
http://lorempixel.com/640/480/business
$randomAvatarImage 随机头像 https://s3.amazonaws.com/uifaces/faces/twitter/johnsmithagency/128.jpg
https://s3.amazonaws.com/uifaces/faces/twitter/xadhix/128.jpg
https://s3.amazonaws.com/uifaces/faces/twitter/martip07/128.jpg
$randomImageUrl 随机图片地址 http://lorempixel.com/640/480
$randomAbstractImage 随机抽象图片 http://lorempixel.com/640/480/abstract
$randomAnimalsImage 随机动物图 http://lorempixel.com/640/480/animals
$randomBusinessImage 随机商务图 http://lorempixel.com/640/480/business
$randomCatsImage 随机猫的图 http://lorempixel.com/640/480/cats
$randomCityImage 随机城市图 http://lorempixel.com/640/480/city
$randomFoodImage 随机食物图 http://lorempixel.com/640/480/food
$randomNightlifeImage 随机夜生活图 http://lorempixel.com/640/480/nightlife
$randomFashionImage 随机时尚图 http://lorempixel.com/640/480/fashion
$randomPeopleImage 随机人物图 http://lorempixel.com/640/480/people
$randomNatureImage 随机自然风景图 http://lorempixel.com/640/480/nature
$randomSportsImage 随机运动图 http://lorempixel.com/640/480/sports
$randomTechnicsImage 随机科技图 http://lorempixel.com/640/480/technics
$randomTransportImage 随机交通图 http://lorempixel.com/640/480/transport
$randomImageDataUri 随机图片data URI data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20baseProfile%3D%22full%22%20width%3D%22undefined%22%20height%3D%22undefined%22%3E%20%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22grey%22%2F%3E%20%20%3Ctext%20x%3D%220%22%20y%3D%2220%22%20font-size%3D%2220%22%20text-anchor%3D%22start%22%20fill%3D%22white%22%3Eundefinedxundefined%3C%2Ftext%3E%20%3C%2Fsvg%3E

# Finance

变量名 说明 结果示例
$randomBankAccount A random 8-digit bank account number 09454073, 65653440, 75728757
$randomBankAccountName A random bank account name (e.g. savings account, checking account) Home Loan Account, Checking Account, Auto Loan Account
$randomCreditCardMask A random masked credit card number 3622, 5815, 6257
$randomBankAccountBic A random BIC (Bank Identifier Code) EZIAUGJ1, KXCUTVJ1, DIVIPLL1
$randomBankAccountIban A random 15-31 character IBAN (International Bank Account Number) MU20ZPUN3039684000618086155TKZ
BR7580569810060080800805730W2
XK241602002200395017
$randomTransactionType A random transaction type (e.g. invoice, payment, deposit) invoice, payment, deposit
$randomCurrencyCode A random 3-letter currency code (ISO-4217) CDF, ZMK, GNF
$randomCurrencyName A random currency name CFP Franc, Cordoba Oro, Pound Sterling
$randomCurrencySymbol A random currency symbol $, £
$randomBitcoin A random bitcoin address 3VB8JGT7Y4Z63U68KGGKDXMLLH5
1GY5TL5NEX3D1EA0TCWPLGVPQF5EAF
14IIEXV2AKZAHSCY2KNYP213VRLD

# Business

变量名 说明 结果示例
$randomCompanyName A random company name Johns - Kassulke, Grady LLC
$randomCompanySuffix A random company suffix (e.g. Inc, LLC, Group) Inc, LLC, Group
$randomBs A random phrase of business speak killer leverage schemas,
bricks-and-clicks deploy markets,
world-class unleash platforms
$randomBsAdjective A random business speak adjective viral, 24/7, 24/365
$randomBsBuzz A random business speak buzzword repurpose, harness, transition
$randomBsNoun A random business speak noun e-services, markets, interfaces

# Catchphrases

变量名 说明 结果示例
$randomCatchPhrase A random catchphrase Future-proofed heuristic open architecture,
Quality-focused executive toolset,
Grass-roots real-time definition
$randomCatchPhraseAdjective A random catchphrase adjective Self-enabling, Business-focused, Down-sized
$randomCatchPhraseDescriptor A random catchphrase descriptor bandwidth-monitored, needs-based, homogeneous
$randomCatchPhraseNoun Randomly generates a catchphrase noun secured line, superstructure,installation

# Databases

变量名 说明 结果示例
$randomDatabaseColumn A random database column name updatedAt, token, group
$randomDatabaseType A random database type tinyint, text
$randomDatabaseCollation A random database collation cp1250_bin, utf8_general_ci, cp1250_general_ci
$randomDatabaseEngine A random database engine MyISAM, InnoDB, Memory

# Dates

变量名 说明 结果示例
$randomDateFuture A random future datetime Tue Mar 17 2020 13:11:50 GMT+0530 (India Standard Time),
Fri Sep 20 2019 23:51:18 GMT+0530 (India Standard Time),
Thu Nov 07 2019 19:20:06 GMT+0530 (India Standard Time)
$randomDatePast A random past datetime Sat Mar 02 2019 09:09:26 GMT+0530 (India Standard Time),
Sat Feb 02 2019 00:12:17 GMT+0530 (India Standard Time),
Thu Jun 13 2019 03:08:43 GMT+0530 (India Standard Time)
$randomDateRecent A random recent datetime Tue Jul 09 2019 23:12:37 GMT+0530 (India Standard Time),
Wed Jul 10 2019 15:27:11 GMT+0530 (India Standard Time),
Wed Jul 10 2019 01:28:31 GMT+0530 (India Standard Time)
$randomWeekday A random weekday Thursday, Friday, Monday
$randomMonth A random month February, May, January

# Domains, Emails and Usernames

变量名 说明 结果示例
$randomDomainName A random domain name gracie.biz, armando.biz, trevor.info
$randomDomainSuffix A random domain suffix org, net, com
$randomDomainWord A random unqualified domain name gwen, jaden, donnell
$randomEmail A random email address Pablo62@gmail.com, Ruthe42@hotmail.com, Iva.Kovacek61@hotmail.com
$randomExampleEmail A random email address from an “example” domain Talon28@example.com, Quinten_Kerluke45@example.net, Casey81@example.net
$randomUserName A random username Jarrell.Gutkowski, Lottie.Smitham24, Alia99
$randomUrl A random URL https://anais.net, https://tristin.net, http://jakob.name

# Files and Directories

变量名 说明 结果示例
$randomFileName A random file name (includes uncommon extensions) neural_sri_lanka_rupee_gloves.gdoc,
plastic_awesome_garden.tif,
incredible_ivory_agent.lzh
$randomFileType A random file type (includes uncommon file types) model, application, video
$randomFileExt A random file extension (includes uncommon extensions) war, book, fsc
$randomCommonFileName A random file name well_modulated.mpg4,
rustic_plastic_tuna.gif,
checking_account_end_to_end_robust.wav
$randomCommonFileType A random, common file type application, audio
$randomCommonFileExt A random, common file extension m2v, wav, png
$randomFilePath A random file path /home/programming_chicken.cpio,
/usr/obj/fresh_bandwidth_monitored_beauty.onetoc,
/dev/css_rustic.pm
$randomDirectoryPath A random directory path /usr/bin, /root, /usr/local/bin
$randomMimeType A random MIME type audio/vnd.vmx.cvsd,
application/vnd.groove-identity-message,
application/vnd.oasis.opendocument.graphics-template

# Stores

变量名 说明 结果示例
$randomPrice A random price between 100.00 and 999.00 531.55, 488.76, 511.56
$randomProduct A random product Towels, Pizza, Pants
$randomProductAdjective A random product adjective Unbranded, Incredible, Tasty
$randomProductMaterial A random product material Steel, Plastic, Frozen
$randomProductName A random product name Handmade Concrete Tuna, Refined Rubber Hat
$randomDepartment A random commerce category Tools, Movies, Electronics

# Grammar

变量名 说明 结果示例
$randomNoun A random noun matrix, bus, bandwidth
$randomVerb A random verb parse, quantify, navigate
$randomIngverb A random verb ending in "-ing" synthesizing, navigating, backing up
$randomAdjective A random adjective auxiliary, multi-byte, back-end
$randomWord A random word withdrawal, infrastructures, IB
$randomWords Some random words Samoa Synergistic sticky copying Grocery,
Corporate Springs,
Christmas Island Ghana Quality
$randomPhrase A random phrase You can't program the monitor without navigating the mobile XML program!,
overriding the capacitor won't do anything, we need to compress the optical SMS transmitter!,
I'll generate the virtual AI program, that should microchip the RAM monitor!

# Lorem Ipsum

变量名 说明 结果示例
$randomLoremWord A random word of lorem ipsum text est
$randomLoremWords Some random words of lorem ipsum text vel repellat nobis
$randomLoremSentence A random sentence of lorem ipsum text Molestias consequuntur nisi non quod.
$randomLoremSentences A random 2-6 sentences of lorem ipsum text Et sint voluptas similique iure amet perspiciatis vero sequi atque. Ut porro sit et hic. Neque aspernatur vitae fugiat ut dolore et veritatis. Ab iusto ex delectus animi. Voluptates nisi iusto. Impedit quod quae voluptate qui.
$randomLoremParagraph A random paragraph of lorem ipsum text Ab aliquid odio iste quo voluptas voluptatem dignissimos velit. Recusandae facilis qui commodi ea magnam enim nostrum quia quis. Nihil est suscipit assumenda ut voluptatem sed. Esse ab voluptas odit qui molestiae. Rem est nesciunt est quis ipsam expedita consequuntur.
$randomLoremParagraphs 3 random paragraphs of lorem ipsum text Voluptatem rem magnam aliquam ab id aut quaerat. Placeat provident possimus voluptatibus dicta velit non aut quasi. Mollitia et aliquam expedita sunt dolores nam consequuntur. Nam dolorum delectus ipsam repudiandae et ipsam ut voluptatum totam. Nobis labore labore recusandae ipsam quo.
Voluptatem occaecati omnis debitis eum libero. Veniam et cum unde. Nisi facere repudiandae error aperiam expedita optio quae consequatur qui. Vel ut sit aliquid omnis. Est placeat ducimus. Libero voluptatem eius occaecati ad sint voluptatibus laborum provident iure.
Autem est sequi ut tenetur omnis enim. Fuga nisi dolor expedita. Ea dolore ut et a nostrum quae ut reprehenderit iste. Numquam optio magnam omnis architecto non. Est cumque laboriosam quibusdam eos voluptatibus velit omnis. Voluptatem officiis nulla omnis ratione excepturi.
$randomLoremText A random amount of lorem ipsum text Quisquam asperiores exercitationem ut ipsum. Aut eius nesciunt. Et reiciendis aut alias eaque. Nihil amet laboriosam pariatur eligendi. Sunt ullam ut sint natus ducimus. Voluptas harum aspernatur soluta rem nam.
$randomLoremSlug A random lorem ipsum URL slug eos-aperiam-accusamus, beatae-id-molestiae, qui-est-repellat
$randomLoremLines 1-5 random lines of lorem ipsum Ducimus in ut mollitia.\nA itaque non.\nHarum temporibus nihil voluptas.\nIste in sed et nesciunt in quaerat sed.