当前位置:网站首页>Postman get started quickly
Postman get started quickly
2022-07-25 17:48:00 【wangmcn】
Postman Quick start
Catalog
- 1、 Preface
- 2、 brief introduction
- 3、 install
- 4、 Basic function
- 4.1、 Request area
- 4.2、 Response area
- 4.3、 Environment variables and global variables
- 4.4、 Import and export
- 4.4.1、 Import
- 4.4.2、 export
- 4.5、 Theme Settings
- 5、 Defining interfaces
- 6、 Analog interface
- 7、 Request interface
- 7.1、Get request ( No parameter )
- 7.2、Get request ( With parameters )
- 7.3、Post request (form-data)
- 7.4、Post request (x-www-form-urlencoded)
- 7.5、 Rely on requests
- 8、 Run set
- 9、 monitor
- 10、 Historical record
1、 Preface
With the development of testing technology , The whole testing industry has higher and higher requirements for testers , In recent years, in addition to ordinary functional tests, testers , They began to ask for interface testing and so on , There are many software for interface testing , There are open source 、 Rechargeable 、 Self developed and so on . This article introduces an excellent , And powerful interface testing tools -Postman.
2、 brief introduction
Postman The first is Google A plug-in exists , Then the team's positioning of the tool , Focus on PC Development and optimization of end , current Google Plug ins are rarely used anymore ,Postman Although it is a commercial software , But for ordinary users , The basic functions are completely enough .
Postman Originally designed for interface testing , So it is widely used by programmers , Track some network requests when developing and debugging network programs , It can effectively help back-end developers conduct interface testing independently .
Postman The main function of :
- 1、Postman Is a powerful web debugging 、HTTP A tool for sending requests and running interface test cases .
- 2、 Able to simulate various HTTP Request Such as GET、POST、PUT、DELETE… wait .
- 3、 Files can also be sent in the request ( picture 、 Text files, etc )、 additional Header etc. , Implement specific interface tests .
- 4、 It can effectively help back-end developers conduct interface testing independently .
- 5、 Provides cloud services , Support data synchronization and teamwork .
- 6、 Provides a wealth of HTML Format report template .
- 7、 Not just interface testing , And it's a API Management tools .
Official website :
https://www.postman.com/
3、 install
Official website download address :
https://www.postman.com/downloads/
After downloading , The default installation is enough .
4、 Basic function
Postman Interface test , Divided into two areas : Request area 、 Response area .
4.1、 Request area
1、Params: Request parameters .
2、Authorization: Authentication , It is mainly used to fill in the user name and password , And some signature verification fields .
3、Headers: Requested header information .
4、Body:post Parameters to be taken when requesting , Put some key-value Key value pair .
- 4.1、form-data: It processes the form data into a message , Label as unit , Separate with separator . You can upload key value pairs separately , You can also upload files directly ( When the upload field is a file , There will be Content-Type To describe the type of document , But the file will not be preserved as history , Only every time you need to send a request , Add files again ).
- 4.2、x-www-form-urlencoded: Corresponding information header Content-Type:application/x-www-form-urlencoded, The data in the form will be converted to key value pairs .
- 4.3、raw: You can upload any type of text , such as Text、JSON、XML etc. , Use JSON The corresponding header of is Content-Type:application/json.
- 4.4、binary: Corresponding information header Content-Type:application/octet-stream, Only binary files can be uploaded , And no key value pair , Only one file can be uploaded at a time , Nor can history be preserved , Submit after each file selection .
5、Pre-request Script: It allows you to customize the request data before the request , This runs before the request , Grammar use JavaScript sentence .
6、Tests: Usually used to write test verification , It runs after the request to verify that the return is correct . Support JavaScript grammar .
7、Settings: Some settings when requesting .
4.2、 Response area
1、Body: Response subject .
- 1.1、Pretty: format JSON、XML、Text And other forms of response content .
- 1.2、Raw: It shows the original data , You can judge whether it is compressed .
- 1.3、Preview: Help you HTML The page is automatically parsed and displayed .
- 1.4、Visualize:Postman Provides a programmable way to visually represent your request response . Added to the request area Tests The visualization code in will be presented in this tab .
2、Cookies: Respond to Cookies.
3、Headers: The header information of the response .
4、Test Results: If in the request area Tests Add test verification in , The test results after executing the interface will be presented in this tab .
4.3、 Environment variables and global variables
Postman Support setting parameters as environment variables or global variables , Convenient interface call .
environment variable : Is a set of variables , Allows you to switch the context of the request .
Global variables : Is a set of variables that are always available in the workspace .
As shown in the figure : You can see that... Has been created 2 Environment variables (DEMO、DEV)
see DEV environment variable , Environment variables can only be selected DEV when , Can be called DEV Variables in the region .
and Globals The global variable is in Collections All interfaces in the collection can be called .
4.4、 Import and export
4.4.1、 Import
Switch to the project area you want to import ( Such as My_Postman2), Click on Import.
Select the interface or variable to import , Click on Import Import .
Successful import .
4.4.2、 export
1、 Export interface
Select specified Collections aggregate , Click on Export.
The default choice is , Click on Export Export .
2、 Export environment variables and public variables
Click on Environments Environmental Science
Select the specified environment variable , Click on Export Export .
Select the specified public variable , Click on Export Export .
All exported files , All are .json The format is suffix .
4.5、 Theme Settings
1、 Open the... In the upper right corner Settings.
2、 Click on Themes,Postman The application can set light or dark themes .
3、 Theme effect .
Light color theme :
Dark theme :
5、 Defining interfaces
Definition API Interface , Also on API Interface management .
1、 Click to enter APIs modular , Create and define interfaces .
2、 Enter the interface name 、 Version number 、 Select the specified schema information, etc .
3、 When I'm done , The API Improve the interface definition , And can be used to API Interface development and testing and other follow-up operations .
6、 Analog interface
because Postman Bring their own Mock Servers( Analog interface service ) function , Therefore, the simulation interface examples requested in this article will be created with this function .
1、 Create an analog interface
Click to enter Mock Servers modular
Start creating the interface to simulate
Give the created Mock Servers Naming , Such as demo_mock.
After creation , Analog interface URL The address is also automatically generated .
It is also automatically added to the environment variable .
2、 Maintain and enhance analog interface content
Interface link has been created , However, you also need to customize the parameters and return values of the link .
Enter into Collections In the assembly , Enhance the analog interface .
Select each interface , Add examples .
for example : Example demo/getpost2
As shown in the figure : All analog interfaces are customized .
7、 Request interface
The simulation interface has been created and the request and return examples have been added , Next, start creating the request interface for interface testing .
newly build Collections aggregate , And named it demo_request.
Start creating request interfaces for interface testing .
7.1、Get request ( No parameter )
Create request :get1, You can see the interface that requests emulation , Return to success .
notes : Because when creating an analog interface , Interface URL The address has been automatically added to the environment variable , At this time, the interface URL Addresses can also be requested by referencing variables . When extracting variables , Use it directly {{ Variable name }} that will do .
7.2、Get request ( With parameters )
Create request :get2, You can see the interface that requests emulation , Return to success .
7.3、Post request (form-data)
Create request :post1, You can see the interface that requests emulation , Return to success .
7.4、Post request (x-www-form-urlencoded)
Create request :post2, You can see the interface that requests emulation , Return to success .
Headers Add... To the message header Content-Type:application/x-www-form-urlencoded
7.5、 Rely on requests
Yes 2 Interface getpost1(Get request , No parameter )、getpost2(Post request , Pass on JSON)
Ask first getpost1, Then request getpost2; however getpost2 There are dependencies in the request parameters of the interface getpost1 Return value of interface , So I'm asking getpost1 after , Extract the return value into the environment variable or public variable , after getpost2 Just quote .
1、 Create request :getpost1
In the request Tests Write scripts in the library :
// obtain body Parameters returned in , Set the parameter to a public variable
varjsonData=JSON.parse(responseBody);
pm.globals.set("global_token",jsonData.mytoken);After running, you can see the interface requesting simulation , Return to success .
The extracted value has been saved in the public variable .
2、 Create request :getpost2
Headers Add... To the message header Content-Type:application/json
In the request Tests In addition to adding extraction variables , Add some assertion statements .
request Tests Script written in :
// obtain body Parameters returned in , Set the parameter to the environment variable
varjsonData=JSON.parse(responseBody);
pm.environment.set("getpost2_environment",jsonData.mytoken);
// obtain body Parameters returned in , Set the parameter to a public variable
varjsonData=JSON.parse(responseBody);
pm.globals.set("getpost2_global",jsonData.mytoken);
// Get the header information parameter in the return , Set the parameter to a public variable
varvalue=postman.getResponseHeader("Content-Type");
pm.globals.set("getpost2_global_type",value);
// Print log
console.log(responseBody);
// Assertion status code 200
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
// Assertion response content
varjsonData=JSON.parse(responseBody);
tests["Check respose msg value"] =jsonData.msg===" Successful operation ";
// Assertion response content - contain
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include(" success ");
});
// Assertion response content - be equal to
pm.test("Body is correct", function () {
pm.response.to.have.body({
"code": 0,
"msg": " Successful operation ",
"mytoken": "eyJhbGciOiJIUzI1NiJ9123"
});
});After running, you can see the interface requesting simulation , Return to success .
notes : When extracting variables , Use it directly {{ Variable name }} that will do .
assertion results :
8、 Run set
Select specified Collections aggregate , Click on Run collection.
After setting , Click on the run .
Run all selected interfaces , And display the test results .
9、 monitor
The monitor allows you to run Collections aggregate , To check its performance and response .
1、 Create monitor
Fill in the monitor name 、 Select the to monitor Collections aggregate 、 Select the environment variable 、 Set the operating frequency, etc .
Monitor creation complete .
2、 You can wait for it to run as planned , You can also manually trigger the operation ( Click on Run).
As shown in the figure : The effect after running , In a healthy state .
10、 Historical record
All operation records will be in History It's shown in the picture .
边栏推荐
猜你喜欢
随机推荐
go语言context控制函数执行超时返回
RestTemplate通过泛型实现POST、PUT、DELETE、GET、集合请求以及文件上传(可批量文件、可带参数)的统一封装(可打印日志)
mongodb 集群及分片
We were tossed all night by a Kong performance bug
Redis源码与设计剖析 -- 18.Redis网络连接库分析
[Hardware Engineer] can't select components?
如何看一本书
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
Brief introduction of bubble sort and quick sort
H5测试点(思维导图)
Redis源码与设计剖析 -- 15.RDB持久化机制
交友活动记录
Several implementations of PHP to solve concurrency problems
Nineteen year old summary
吴恩达机器学习编程作业无法暂停pause问题解决
EDI 对接CommerceHub OrderStream
【硬件工程师】DC-DC隔离式开关电源模块为什么会用到变压器?
Redistemplate solves the problem of oversold inventory in the seckill system with high speed - redis transaction + optimistic lock mechanism
十九岁的总结
PageHelper can also be combined with lambda expressions to achieve concise paging encapsulation

![[Hardware Engineer] can't select components?](/img/bd/fdf62b85c082f7e51bf44737f1f787.png)







