当前位置:网站首页>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 .
边栏推荐
猜你喜欢
Gracefully transform the SMS business module and start the strategic mode!
“微博评论”的高性能高可用计算架构
微博系统中”微博评论“的高性能高可用计算架构
Intranet penetration (NC)
Welcome the "top ten" of the Municipal Association for science and technology • pay tribute to Lu Yi, a scientific and technological worker: an explorer guarding the transmission security of the power
sql刷题595. 大的国家
软件测试 接口测试 Jmeter 5.5 安装教程
收藏!这些提高程序员生产力的工具你用过吗?
Wireshark data analysis and forensics information pacapng
Why does copying files on a shared folder on a local area network (ERP server) result in the loss of the local Internet
随机推荐
Ansible自动化运维
Paper writing tool: latex online website
Qt5.14.2 error connecting to the MySQL database of Ubuntu 20.04
Go zero micro Service Practice Series (VII. How to optimize such a high demand)
Grep tool
How can the local / park do a good job in industrial analysis?
Design of Distributed Message Oriented Middleware
C指针进阶2-->函数指针数组 回调函数简化计算器代码,基于回调函数模拟实现qsort函数
Does Australia require that PVC plastic sheets comply with as/nzs 1530.3 with a flame spread index of 0?
111.简易聊天室14:聊天室客户端
啃下大骨头——排序(一)
CE第二次作业
Constexpr function
自己收藏的一些网址
2022年PMP项目管理考试敏捷知识点(5)
十大券商:“推土机行情”再现
基金的估值,费用,会计核算
分布式消息中间件设计
math_ Basic elementary function graph (power function / exponent / logarithm / trigonometry / inverse trigonometry)
股票开户安全吗?上海股票开户。