当前位置:网站首页>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 .
边栏推荐
- Redis client
- Constexpr function
- Detailed description of gaussdb (DWS) complex and diverse resource load management methods
- 動態代理的實現原理
- 基金的利润分配与税收
- error: C2665: “QMessageBox::critical”: 4 个重载中没有一个可以转换所有参数类型
- 写论文工具:LaTex在线网站
- Cloud native enthusiast weekly: cool collection of grafana monitoring panels
- CE第二次作业
- [learn FPGA programming from scratch -51]: high level chapter - FPGA development based on IP core - what is FPGA IP core (soft core, fixed core, hard core) and learning methods
猜你喜欢

Ansible自动化运维

Hematemesis finishing: a rare map of architects!

Intranet penetration (NC)

Gracefully transform the SMS business module and start the strategic mode!

论文阅读《Large-Scale Direct SLAM with Stereo Cameras》
discrete "digital signal"]"/>Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]

sql刷题595. 大的国家
Evolution from stand-alone to distributed database storage system

Touch key and key control corresponding LED status reversal

Still stay up late every day and work overtime to make statements? In fact, you don't know how to make reports efficiently
随机推荐
Vs cannot locate program input point to DLL
Mysql database: partition
error: C2665: “QMessageBox::critical”: 4 个重载中没有一个可以转换所有参数类型
基金的估值,费用,会计核算
Uniapp copy contents to clipboard
Laravel 创建自己的 Facade 扩展 geoip 根据 IP 获取国家、地域、城市信息
Number theory - division and blocking
开源了 | 文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
How to use filters in jfinal to monitor Druid for SQL execution?
Become the only key
Paper writing tool: latex online website
Sword finger offer 38 Arrangement of strings
Talk about auto in MySQL in detail_ What is the function of increment
Wireshark data analysis and forensics information pacapng
Qdomdocument and qdomnode are used in QT to read XML
C language tutorial – -6 loop statement
Leetcode 1385. 两个数组间的距离值
Go zero micro Service Practice Series (VII. How to optimize such a high demand)
Wechat applet: (update) cloud development wechat group contacts
動態代理的實現原理