当前位置:网站首页>Parameterization of postman
Parameterization of postman
2022-07-06 09:07:00 【Automated test seventh uncle】
Preface
friends , Long time no see , Today, I want to talk with you postman A parameterized , In the interface test , Some parameters are unique values for each send request , At this time, the test data can be parameterized ,postman There are three main forms of parameterization .
1、 Built in variable implementation
The built-in variable is postman Built in system variables , But we can't make an accurate comparison
Variable Name | Description | Examples |
{ {$guid}} | Add one V4 Style GUID | “611c2e81-2ccb-42d8-9ddc-2d0bfa65c1b4” |
{ {$timestamp}} | Add the current timestamp , Accurate to seconds | 1562757107 , 1562757108 , 1562757109 |
{ {$randomint}} | add to 0-1000 Random integer between | 0-1000 Random integer between |
{ {$randomFullName}} | Random full name ( name surname ) | Connie Runolfsdottir , Sylvan Fay , Jonathon Kunze |
{ { $randomBoolean}} | Random Boolean values (true/false) | true , false , false , true |
More built-in variable references :https://blog.csdn.net/minzhung/article/details/102531880 Built in variables are generally placed in request in
2、Pre-request-Script The tab uses code to realize
The execution sequence of a single request is shown in the following figure :

Pre-request-Script→request→response→Tests
This is a more recommended parameterization method , You can write your own script , Improved plasticity ,
It is worth noting that when the interface test is executed, the interface will execute the code here first , Then send the request , Finally, make an assertion , And test All support js grammar
Pre-request-Script What to do before executing the interface request , and tests Is to perform the requested operation , Built in variables are generally placed in request in , We
You can also use code in pre-request-Script To realize , The advantage of code implementation is that it can be reused , Here are some examples :
Example 1 、Pre-request-Script First define the current time and get , Set the current time as a global variable and then transfer it to the request parameters , And then in Tests Assert in


3、 The following is the implementation of other parameterization methods

The code is as follows
var now_time = Date.now();
pm.globals.set("now_time", now_time);
const guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
.replace(/x/g, () => (Math.floor(Math.random() * 16)).toString(16))
.replace(/y/g, () => (Math.floor(Math.random() * 4 + 8)).toString(16));
pm.globals.set("guid_value", guid);
const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
pm.globals.set("random_number", randomInt(8,14) );
const getRandomValue = list => list[randomInt(0, list.length - 1)];
const charsInName = [' king ',' Li ',' Zhang '];
pm.globals.set("people_name", getRandomValue(charsInName) );
var mobile_num = `13${randomInt(500000000, 599999999)}`;
pm.globals.set('mobile_num',mobile_num);
const sleep = (milliseconds) => {
const start = Date.now();
while (Date.now() <= start + milliseconds) {}
};
sleep(5000);4、 External files
4.1 adopt csv Documents or json Format file to achieve parameterization
csv The use of , First, set the fields to be searched and the search results in the file

The key self should be separated by English commas , The first line writes the defined parameter variables , Remember to use utf-8 The encoding format of 、.csv The file suffix is saved , Click on runner Button


You can also view the specific running results on the console

If the expected result of the assertion is also written into the file , It can also be in Tests Called in assertion , No more examples here

4.2 External files can also be accessed through json Format file to achieve parameterization , Remember to check whether the file is json


It is worth noting that iteration Set the number of iterations , Each iteration will use a line in your data file , If the number of iterations exceeds the number of lines in the data file , I will reuse the last row of data
summary
So much for today's article , Remember to like collection comments and pay attention to your favorite friends , Pay attention to the different surprises I give you every day .

边栏推荐
- Using C language to complete a simple calculator (function pointer array and callback function)
- Advance Computer Network Review(1)——FatTree
- Advance Computer Network Review(1)——FatTree
- After reading the programmer's story, I can't help covering my chest...
- [text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
- Intel Distiller工具包-量化实现1
- LeetCode:162. 寻找峰值
- Intel distiller Toolkit - Quantitative implementation 1
- [Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
- 在QWidget上实现窗口阻塞
猜你喜欢

SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date

Pytest参数化你不知道的一些使用技巧 /你不知道的pytest

BMINF的後訓練量化實現
![[oc]- < getting started with UI> -- learning common controls](/img/2c/d317166e90e1efb142b11d4ed9acb7.png)
[oc]- < getting started with UI> -- learning common controls

Advanced Computer Network Review(4)——Congestion Control of MPTCP

Nacos 的安装与服务的注册

Intel Distiller工具包-量化实现2
![[embedded] print log using JLINK RTT](/img/22/c37f6e0f3fb76bab48a9a5a3bb3fe5.png)
[embedded] print log using JLINK RTT

使用latex导出IEEE文献格式

MongoDB 的安装和基本操作
随机推荐
Advanced Computer Network Review(3)——BBR
IJCAI2022论文合集(持续更新中)
Digital people anchor 618 sign language with goods, convenient for 27.8 million people with hearing impairment
What is an R-value reference and what is the difference between it and an l-value?
CUDA implementation of self defined convolution attention operator
Pytest parameterization some tips you don't know / pytest you don't know
Compétences en mémoire des graphiques UML
LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
[MySQL] limit implements paging
Using C language to complete a simple calculator (function pointer array and callback function)
LeetCode:673. Number of longest increasing subsequences
LeetCode:41. 缺失的第一个正数
AcWing 2456. 记事本
LeetCode41——First Missing Positive——hashing in place & swap
LeetCode:剑指 Offer 03. 数组中重复的数字
随手记01
【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Intel Distiller工具包-量化实现1
CUDA实现focal_loss