【Postman】动态变量(也称Mock函数)

Postman 使用faker 库来生成样本数据,包括随机姓名、地址、电子邮件地址等等。您可以多次使用这些预定义变量来为每个请求返回不同的值。

您可以像使用 Postman 中的任何其他变量一样使用这些变量。它们的值是在执行时生成的,它们的名称以 符号开头,例如 符号开头,例如 符号开头,例如guidor $timestamp。

以下是在请求/收集运行期间随机生成其值的动态变量列表。

要在预请求或测试脚本中使用动态变量,您需要pm.variables.replaceIn()使用pm.variables.replaceIn(‘{{$randomFirstName}}’).

常见的

变量的名称描述例子
$guid uuid-v4风格指南 “611c2e81-2ccb-42d8-9ddc-2d0bfa65c1b4”、 “3a721b7f-7dc9-4c45-9777-516942b98e0d”、“22eca807-006b-47df-9511-e92e37f5071a”
$timestamp 当前的 UNIX 时间戳(以秒为单位) 1562757107, 1562757108, 1562757109
$isoTimestamp UTC 时间为零的当前 ISO 时间戳 2020-06-09T21:10:36.177Z、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, false, true
$randomInt 0 到 1000 之间的随机整数 802, 494, 200
$randomColor 随机的颜色 “red”, “fuchsia”, “grey”
$randomHexColor 一个随机的十六进制值 “#47594a”, “#431e48”, “#106f21”
$randomAbbreviation 随机缩写 SQL, PCI, JSON

互联网和 IP 地址

变量的名称描述例子
$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 一个随机的两个字母的语言代码 (ISO 639-1) “ny”, “sr”, “si”
$randomUserAgent 随机用户代理 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 随机语义版本号 7.0.5, 2.5.8, 6.4.9

名称

变量的名称描述例子
$randomFirstName 一个随机的名字 Ethan, Chandler, Megane
$randomLastName 一个随机的姓氏 Schaden, Schneider, Willms
$randomFullName 一个随机的名字和姓氏 Connie Runolfsdottir, Sylvan Fay, Jonathon Kunze
$randomNamePrefix 随机名称前缀 Dr., Ms., Mr.
$randomNameSuffix 随机名称后缀 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 一个随机的十位数电话号码 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 一个随机的两个字母的国家代码 (ISO 3166-1 alpha-2) CV, MD, TD
$randomLatitude 随机纬度坐标 55.2099, 27.3644, -84.7514
$randomLongitude 随机经度坐标 40.6609, 171.7139, -159.9757

图片

变量的名称描述例子
$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 随机图片的 URL http://lorempixel.com/640/480
$randomAbstractImage 随机抽象图像的 URL http://lorempixel.com/640/480/abstract
$randomAnimalsImage 随机动物图片的 URL http://lorempixel.com/640/480/animals
$randomBusinessImage 随机库存商业图片的 URL http://lorempixel.com/640/480/business
$randomCatsImage 随机猫图片的 URL http://lorempixel.com/640/480/cats
$randomCityImage 随机城市图片的 URL http://lorempixel.com/640/480/city
$randomFoodImage 随机食物图片的 URL http://lorempixel.com/640/480/food
$randomNightlifeImage 随机夜生活图片的 URL http://lorempixel.com/640/480/nightlife
$randomFashionImage 随机时尚图片的 URL http://lorempixel.com/640/480/fashion
$randomPeopleImage 一个人的随机图像的 URL http://lorempixel.com/640/480/people
$randomNatureImage 随机自然图像的 URL http://lorempixel.com/640/480/nature
$randomSportsImage 随机运动图像的 URL http://lorempixel.com/640/480/sports
$randomTransportImage 随机交通图片的 URL http://lorempixel.com/640/480/transport
$randomImageDataUri 随机图像数据 URI data:image/svg+xml;charset=UTF8,%。。。

补充$randomImageDataUri例子如下:

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

金融

变量的名称描述例子
$randomBankAccount 一个随机的 8 位银行帐号 09454073, 65653440, 75728757
$randomBankAccountName 一个随机的银行账户名称(储蓄账户、支票账户) Home Loan Account, Checking Account, Auto Loan Account
$randomCreditCardMask 一个随机屏蔽的信用卡号 3622, 5815, 6257
$randomBankAccountBic 随机 BIC(银行识别码) EZIAUGJ1, KXCUTVJ1, DIVIPLL1
$randomBankAccountIban 一个随机的 15-31 个字符的 IBAN(国际银行帐号) MU20ZPUN3039684000618086155TKZ、BR7580569810060080800805730W2、XK241602002200395017
$randomTransactionType 随机交易类型(发票、付款、存款) invoice, payment, deposit
$randomCurrencyCode 一个随机的 3 个字母的货币代码 (ISO-4217) CDF, ZMK, GNF
$randomCurrencyName 随机货币名称 CFP Franc, Cordoba Oro, Pound Sterling
$randomCurrencySymbol 随机货币符号 $, £
$randomBitcoin 一个随机的比特币地址 3VB8JGT7Y4Z63U68KGGKDXMLLH5、1GY5TL5NEX3D1EA0TCWPLGVPQF5EAF、14IIEXV2AKZAHSCY2KNYP213VRLD

商业

变量的名称描述例子
$randomCompanyName 一个随机的公司名称 Johns - Kassulke,Grady LLC
$randomCompanySuffix 一个随机的公司后缀(Inc, LLC, Group) Inc, LLC, Group
$randomBs 商务演讲的随机短语 killer leverage schemas,、bricks-and-clicks deploy markets,world-class unleash platforms
$randomBsAdjective 一个随机的商务口语形容词 viral, 24/7, 24/365
$randomBsBuzz 一个随机的企业说流行语 repurpose, harness, transition
$randomBsNoun 一个随机的商业名词 e-services, markets, interfaces

口头禅

变量的名称描述例子
$randomCatchPhrase 随机的流行语 Future-proofed heuristic open architecture,Quality-focused executive toolset,Grass-roots real-time definition
$randomCatchPhraseAdjective 一个随机的流行语形容词 Self-enabling, Business-focused,Down-sized
$randomCatchPhraseDescriptor 随机流行语描述符 bandwidth-monitored, needs-based, homogeneous
$randomCatchPhraseNoun 随机生成一个流行语名词 secured line, superstructure,installation

数据库

变量的名称描述例子
$randomDatabaseColumn 随机数据库列名 updatedAt, token, group
$randomDatabaseType 随机数据库类型 tinyint,text
$randomDatabaseCollation 随机数据库整理 cp1250_bin, utf8_general_ci, cp1250_general_ci
$randomDatabaseEngine 随机数据库引擎 MyISAM, InnoDB, Memory

日期

变量的名称描述例子
$randomDateFuture 一个随机的未来日期时间 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 随机过去的日期时间 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 一个随机的最近日期时间 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 一个随机的工作日 Thursday, Friday, Monday
$randomMonth 随机的一个月 February, May, January

域、电子邮件和用户名

变量的名称描述例子
$randomDomainName 随机域名 gracie.biz, armando.biz, trevor.info
$randomDomainSuffix 随机域后缀 org, net, com
$randomDomainWord 一个随机的不合格域名 gwen, jaden, donnell
$randomEmail 一个随机的电子邮件地址 Pablo62@gmail.com, Ruthe42@hotmail.com, Iva.Kovacek61@hotmail.com
$randomExampleEmail 来自“示例”域的随机电子邮件地址 Talon28@example.com, Quinten_Kerluke45@example.net, Casey81@example.net
$randomUserName 随机用户名 Jarrell.Gutkowski, Lottie.Smitham24, Alia99
$randomUrl 随机网址 https://anais.net, https://tristin.net, http://jakob.name

文件和目录

变量的名称描述例子
$randomFileName 随机文件名(包括不常见的扩展名) neural_sri_lanka_rupee_gloves.gdoc,plastic_awesome_garden.tif,incredible_ivory_agent.lzh
$randomFileType 随机文件类型(包括不常见的文件类型) model, application, video
$randomFileExt 随机文件扩展名(包括不常见的扩展名) war, book, fsc
$randomCommonFileName 随机文件名 well_modulated.mpg4,rustic_plastic_tuna.gif,checking_account_end_to_end_robust.wav
$randomCommonFileType 一种随机的、常见的文件类型 application, audio
$randomCommonFileExt 一个随机的通用文件扩展名 m2v, wav, png
$randomFilePath 随机文件路径 /home/programming_chicken.cpio,/usr/obj/fresh_bandwidth_monitored_beauty.onetoc,/dev/css_rustic.pm
$randomDirectoryPath 随机目录路径 /usr/bin, /root, /usr/local/bin
$randomMimeType 随机 MIME 类型 audio/vnd.vmx.cvsd,application/vnd.groove-identity-message,application/vnd.oasis.opendocument.graphics-template

专卖店

变量的名称描述例子
$randomPrice 0.00 到 1000.00 之间的随机价格 531.55, 488.76, 511.56
$randomProduct 随机产品 Towels, Pizza, Pants
$randomProductAdjective 随机产品形容词 Unbranded, Incredible, Tasty
$randomProductMaterial 随机产品材质 Steel, Plastic, Frozen
$randomProductName 一个随机的产品名称 Handmade Concrete Tuna,Refined Rubber Hat
$randomDepartment 一个随机的商业类别 Tools, Movies, Electronics

语法

变量的名称描述例子
$randomNoun 随机名词 matrix, bus, bandwidth
$randomVerb 随机动词 parse, quantify, navigate
$randomIngverb 一个以随机结尾的动词-ing synthesizing, navigating, backing up
$randomAdjective 一个随机的形容词 auxiliary, multi-byte, back-end
$randomWord 一个随意的词 withdrawal, infrastructures, IB
$randomWords 一些随意的词 Samoa Synergistic sticky copying Grocery,Corporate Springs,Christmas Island Ghana Quality
$randomPhrase 一个随机的短语 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 网上随便的一句话 est
$randomLoremWords 互联网本身文字的一些随机词 vel repellat nobis
$randomLoremSentence 网上随便的一句话 Molestias consequuntur nisi non quod.
$randomLoremSentences 网上随机的2到6句话 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 互联网本身的随机一段 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个随机段落 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 互联网上的随机文本量 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 一个随机的网站 URL slug eos-aperiam-accusamus, beatae-id-molestiae, qui-est-repellat
$randomLoremLines 1 到 5 行 lorem ipsum 的随机行 Ducimus in ut mollitia.\nA itaque non.\nHarum temporibus nihil voluptas.\nIste in sed et nesciunt in quaerat sed.

自研产品推荐

历时一年半多开发终于smartApi-v1.0.0版本在2023-09-15晚十点正式上线
smartApi是一款对标国外的postman的api调试开发工具,由于开发人力就作者一个所以人力有限,因此v1.0.0版本功能进行精简,大功能项有:

  • api参数填写
  • api请求响应数据展示
  • PDF形式的分享文档
  • Mock本地化解决方案
  • api列表数据本地化处理
  • 再加上UI方面的打磨

为了更好服务大家把之前的公众号和软件激活结合,如有疑问请大家反馈到公众号即可,下个版本30%以上的更新会来自公众号的反馈。
嗯!先解释不上服务端原因,API调试工具的绝大多数时候就是一个数据模型、数据处理、数据模型理解共识的问题解决工具,所以作者结合自己十多年开发使用的一些痛点来打造的,再加上服务端开发一般是面向企业的,作者目前没有精力和时间去打造企业服务。再加上没有资金投入所以服务端开发会滞后,至于什么时候会进行开发,这个要看募资情况和用户反馈综合考虑。虽然目前国内有些比较知名的api工具了,但作者使用后还是觉得和实际使用场景不符。如果有相关吐槽也可以在作者的公众号里反馈蛤!
下面是一段smartApi使用介绍:
在这里插入图片描述

下载地址:

https://pan.baidu.com/s/1iultkXqeLNG4_eNiefKTjQ?pwd=cnbl

posted @ 2022-06-06 22:21  lichong951  阅读(69)  评论(0编辑  收藏  举报  来源