当前位置:网站首页>Software testing interface testing postman testing tool interface testing process execution interface testing interface associated environment variables and global variables built-in dynamic parameter
Software testing interface testing postman testing tool interface testing process execution interface testing interface associated environment variables and global variables built-in dynamic parameter
2022-06-29 23:19:00 【Uncle Ye in ten days】
List of articles
- 1 Introduction and classification of interface testing
- 2 The flow of interface testing and the design of use cases
- 3 mall_cms_v2 Interface
- 4 Postman Interface is introduced
- 5 Postman Perform interface tests
- 6 Postman Environment variables and global variables
- 7 Interface Association
- 8 Postman Built in dynamic parameters and automatic dynamic parameters
- 9 Postman Assertion
- 10 Postman Batch run test cases
1 Introduction and classification of interface testing
Interface test is a kind of test between system components .
classification :
Test the external interface : Test the interface between the tested system and the external system . Generally, you only need to test the forward use case .
Test the internal interface :
(1) The internal interface is only provided for the system . Generally, you only need to test the forward use case .
(2) Internal interfaces are provided for external systems . The test must be very comprehensive .
2 The flow of interface testing and the design of use cases
1 Get the interface API file ( Get it through the bag grabbing tool ), Familiar with interface business , Address of the interface , Authentication method , Enter the reference , The ginseng , Error code .
2 Write interface use cases and review .
Ideas . Forward use cases , Enter the normal parameters , The interface can successfully return data .
Reverse use cases have authentication reverse use cases 、 Parameter reverse use case 、 Error code coverage and other error scenarios .
The authentication code in the reverse authentication case repository is empty , The authentication code is wrong and expired .
Parameter reverse use cases include empty parameters , Parameter type exception , Abnormal length .
Error code coverage depends on the business .
Other error scenarios include interface blacklists , Interface call limit and paging scenario .
3 Use the interface test case tool Postman Perform interface tests .
4 Postman+Newman+Jenkins Implementing continuous integration , And output parameter report and send email .
3 mall_cms_v2 Interface
The interfaces tested are as follows :
https://documenter.getpostman.com/view/12387168/TzzDKb12#7f0beb33-e365-420b-bbcf-67df9c87749e
name,password,token.
4 Postman Interface is introduced
Home Home page
workpaces working space
collections aggregate , Project collection .
APIs api file .
Environments environment variable , Global variables .
Mock Servers Virtual server .
Monitors Monitor .
Hoistory Historical record .
5 Postman Perform interface tests
5.1 Request page module
Parsam:get Ask for a reference
authorization: authentication
headers: Request header
Body:post Ask for a reference , The parameter transfer method is shown in the following table :
| The way | describe |
|---|---|
| form-data | Key value pairs and file transfer parameters are available |
| x-www-from-urlencoded | Parameters can only be passed in key value pairs |
| raw | json,text,xml,html,javascript |
| binary | Pass the file to the parameter in binary mode |
The specific location is shown in the figure below :
pre-request-script: Scripts between requests
tests: Assertion after request
cookies: Used to manage Cookie Information
Postman The request page module is shown in the following figure :
5.2 Response page module
Body: The data returned by the interface , The form of parameter transfer is shown in the following table :
| The way | describe |
|---|---|
| Pretty | With json,html,xml View the returned data in different formats |
| Raw | View the returned data as text |
| PreView | View the returned data as a web page |

Cookies: Responsive Cookies Information .
Headers: Response head .
Test Results: The result of the assertion .
200 Is the status code
OK Status information
12.64s Response time
347.84kb Is the number of bytes in response
The response page module is shown in the figure below :
get Request and post Differences in requests :
1 get The request is to get data ,post The request is to submit data .
2 The essential difference is that the way of passing parameters is different .
get The request follows the address bar with ? In the way of transmission , Use... Between multiple parameters & Separate .post The request is in body Pass parameters as a form .
post Request example , The request module is shown in the figure below :
The response module is shown in the figure below :
6 Postman Environment variables and global variables
6.1 environment variable
First of all , Add multiple environment variables , Here's the picture :
second , Set variables and variable values in environment variables , Variable is url, Variable value is api.weixin.qq.com, Here's the picture :
Third , stay Collections Switch environment variables , Here's the picture :

6.2 The difference between environment variables and global variables
environment variable : Environment variables are global variables
Global variables : Global variables are variables that can be accessed in any interface
Get the values of environment variables and global variables :{ { Variable name }}
7 Interface Association
7.1 Use json The extractor implements Interface Association
With 152.136.185.210:4000/login As an example
Assertion after request
First step , View the results after the response , The following code :
console.log(responseBody);
The second step , To obtain the access_token The format of the value of is converted to the data of the object , The results are stored in result variable , The following code :
var result = JSON.parse(responseBody)
The third step , take access_token Set to global variable , The following code :
pm.globals.set("token", "result.token");
Sum up , stay Request module Medium Tests Sub module Enter the following code in :
// View the results after the response
console.log(responseBody);
// Convert the returned string format data into object data
var result = JSON.parse(responseBody)
// hold token Set the value in to the global variable
pm.globals.set("token", "result.token");
The operation results are as follows :
Check whether the global variable has been added token, Here's the picture :
Of the above two pictures token Agreement , It is proved that token Global variables !
That is, other interfaces are used directly token, Use format { {token}}, Implements the interface Association .
7.2 Implement interface association using regular expression extractor
// Implement interface association using regular expression extractor ,math matching .
var result = responseBody.match(new RegExp('"access_token":"(.*?)"'));
// Obtain authentication code
console.log(result[1])
// Set the authentication code as a global variable
pm.globals.set("access_token", result[1]);
Analyze the above code :
responseBady Return results ,math Method compares the result with token matching , So as to obtain token, then token Set to global variable .
stay Console The running result of the box is shown in the following figure :
You can also view in the global variables page token value , Here's the picture :
8 Postman Built in dynamic parameters and automatic dynamic parameters
8.1 Built in dynamic parameters
postman The built-in dynamic parameters are written in the request module Body In the submodule row light , With json Form into , The built-in dynamic parameters are as follows :
{
{
$timestamp}} Generate timestamp of current time
{
{
$randomInt}} Generate 0-1000 Random number between
{
{
$guid}} Generate random GUID character string
8.2 Custom dynamic parameters
Custom dynamic parameters are usually written on the request page Pre-request Script in , The following code :
// Get the timestamp manually
var times = Date.now()
// Set to global variable
pm.globals.set("times", times);
Use times The format of global variables is as follows :
{
{
times}}
notes :
(1) Implementation of business closed loop . Compliance creation 、 modify 、 The order of query and modification .
(2) Upload files , As shown in the figure below :
9 Postman Assertion
9.1 frequently-used 6 Kind of assertion
| Assertion | describe |
|---|---|
| Status code: Code is 200 | Determine whether the status code is 200 |
| Response boby: Contains string | Determine whether the response content contains string character string |
| Response boby: JSON value check | Determine the response content json Whether it is the corresponding value |
| Response boby: Is equal to string | Determine whether the response content is equal to string character string |
| Response headers: Content-Type header check | Determine whether the response header contains Content-Type header |
| Response time is less than 200ms | Determine if the response time is less than 200ms |
9.2 Assertion mode of dynamic parameters
In general , We all set dynamic parameters to global variables , That is, you need to call the global variable in the assertion , The method is as follows :
firstly , Use Postman The built-in method for obtaining global variables in , as follows :
pm.globals.get("variable_key");
second , Use the method of list value , as follows :
globals["variable_key"]
third , Using object references , as follows :
globals.variable_key
9.3 Global assertion
Select... In the project Edit, Here's the picture :
stay Tests Set the global assertion under the module , That is, each interface will make the global assertion . In a general way , We set the status code assertion to global assertion , Here's the picture :
10 Postman Batch run test cases
Added to the runner in 
If there is an uploaded file in the test case , It needs to be adjusted in the settings , First, find the setting interface , Here's the picture :
choice settings.
then , allow Postman Read external files , Here's the picture :
Last , Put the files to be uploaded in D:\Users\DELL\Postaman\files Directory .
边栏推荐
- 字节云数据库未来方向的探索与实践
- Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
- 深入解析kubernetes controller-runtime
- 众昂矿业:萤石助力氟产业锂电建设发展
- “微博评论”的高性能高可用计算架构
- Static keyword continuation, inheritance, rewrite, polymorphism
- MySQL lock common knowledge points & summary of interview questions
- [cooking record] - hot and sour cabbage
- 写论文工具:LaTex在线网站
- Paper writing tool: latex online website
猜你喜欢

CE第二次作业

地方/园区如何做好产业分析?

软件测试 接口测试 Postman测试工具 接口测试的流程 执行接口测试 接口关联 环境变量和全局变量 内置动态参数以及自动有的动态参数

语音信号处理(二): 发声生理、听觉生理与听觉心理

收藏!这些提高程序员生产力的工具你用过吗?

Go zero micro Service Practice Series (VII. How to optimize such a high demand)

Qt5.14.2 error connecting to the MySQL database of Ubuntu 20.04

AI scene Storage Optimization: yunzhisheng supercomputing platform storage practice based on juicefs

Open source the Ernie tiny lightweight technology of "Wenxin big model", which is accurate and fast, with full effect

优雅的改造短信业务模块,策略模式走起!
随机推荐
股票开户安全吗?上海股票开户。
Golang code specification sorting
字节云数据库未来方向的探索与实践
记一次排查线上MySQL死锁过程,不能只会curd,还要知道加锁原理
I hope you have no regrets about the regrettable things in the University
Uniapp copy contents to clipboard
Sword finger offer 38 Arrangement of strings
Error: c2665: "qmessagebox:: critical": none of the four overloads can convert all parameter types
CE第二次作业
AI scene Storage Optimization: yunzhisheng supercomputing platform storage practice based on juicefs
剑指 Offer 38. 字符串的排列
Ansible automatic operation and maintenance
label问题排查:打不开标注好的图像
error: C2665: “QMessageBox::critical”: 4 个重载中没有一个可以转换所有参数类型
InfluxDB时序数据库系统
论文阅读《Large-Scale Direct SLAM with Stereo Cameras》
M1笔记本居家办公的痛点及解决方案 | 社区征文
MySQL lock common knowledge points & summary of interview questions
How ZABBIX 5.0 adds esxi6.7 to monitoring
Evaluation of powerful and excellent document management software: image management, book management and document management