Bootstrap

postman+python实现接口接口自动化

很多人会问,postman可以自己执行,为啥还需要写代码呢,话虽如此,但是作为技术人,工具毕竟只是辅助,自己写的话,更具有灵活性额,下面直接讲干货吧

实现批量发送多个请求

1、首选在postman里新建几个用例,以post和get为例,见下图:

2、在用例集中分别操作1、2,以collection2.1的形式导出为test.json

3、下面开始写代码额,直接上代码

import requests
import json
import numpy as np
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
def readJson():
    return json.load( open("test.json",encoding='utf-8',mode = 'r'))['item']

def three_get():
    for item in readJson():
        #post请求中data的类型必须是json
        if item['request']['method']=='POST':
 
;