Postman script batch transfer interface automation use case

1 Introduction

The author has previously developed a tool for generating interface use cases - API Interface Use Case Generator, which converts existing Postman scripts into interface use cases. This article introduces another recently developed tool that converts Postman's json script files in batches to generate interface use cases - APICase-PostmanForJSON.

2. Introduction

 If you want to learn automated testing, here I recommend a set of videos for you. This video can be said to be the number one automated testing tutorial on the entire network at station B. At the same time, the number of people online has reached 1,000, and there are notes to collect and share with you. Dashen Technical Exchange: 798478386   

[Updated] The most detailed collection of practical tutorials for automated testing of Python interfaces taught by station B (the latest version of actual combat)_哔哩哔哩_bilibili [Updated] The most detailed collection of practical tutorials for automated testing of Python interfaces taught by station B (actual combat) The latest version) has a total of 200 videos, including: 1. Why should interface automation be done in interface automation, 2. The overall view of request in interface automation, 3. Interface combat in interface automation, etc. UP hosts more exciting videos, please pay attention to UP account . https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337.search-card.all.click   APICase-PostmanForJSON, written in Python, uses Tkinter for GUI packaging.

Features:

1、支持 GET、POST、PUT、DELETE 方法

2、支持 带参数[Params]、带请求头[Header]、带请求体[Body]

3、支持 POST方式的文件上传接口[form-data]

4、支持 JSON格式类型:{}、[]、[{}]

5、支持 获取环境变量[环境变量文件-Initial value]

6、支持 获取全局变量[Variables]

7、支持 依赖接口的指定值获取[Tests]
示例:
var jsonData =JSON.parse(responseBody);
postman.setGlobalVariable("pressure",jsonData.data.pressure);

var jsonData =JSON.parse(responseBody);
pm.environment.set("pressure",jsonData.data.pressure);

var jsonData =JSON.parse(responseBody);
pm.globals.set("pressure",jsonData.data.pressure);

var jsonData =JSON.parse(responseBody);
pm.collectionVariables.set("pressure",jsonData.data.pressure);

8、支持 按接口或流程来生成用例

9、支持 按生成用例方式为流程时,提取返回值可以是值或方法
示例:
值:1006
方法:$('now',2,'res_body.data.pressure')

10、支持 自定义提取接口返回值
示例:
data
data.albumId
data[0].categoryId

11、支持 单接口缺省参数自动填充

12、支持 Postman接口脚本的两种方式[Add request、Add example]

13、支持 多接口[乱序],生成用例时相同接口归类

 3. Get started quickly

Open APICase-PostmanForJSON.

 The main thing is to import Postman’s json file (the interface file is required, and the environment variable file is optional), and set whether it is an interface or a process according to the way to generate the use case. Define the extraction value, fill in the value you want, and then click Run. The progress bar can display the progress in real time during the running process.

The following figure is an example of an interface of Postman, you can see that the request is successful and the return value.

Export Postman's interface and environment variable json files.

 

Use APICase-PostmanForJSON to convert the exported json file into an interface use case.

Import the json file, set the custom extraction value, and generate the use case as the interface.

After clicking Run, the use case will start to be generated. The running log will first count how many interfaces there are, and then print out the interface information in real time. 

 

After the use case is generated, print out the use case file path.

Open the use case file, you can see the format of the generated use case, which is generated according to the interface, that is, the same interface is classified into one category, and you can see that there are two types of interfaces, and the custom extraction value is also extracted.

 

If it is a process according to the generated use case method.

 Open the use case file, and you can see how many sheets are generated for as many interfaces as there are. This example has 4 interfaces, so 4 sheets will be generated (each interface is 1 sheet).

 

 

 

Guess you like

Origin blog.csdn.net/m0_73409141/article/details/132562170