httprunner上传文件multipart/form-data

Content-Type = multipart/form-data
#上传文件


Rquest Payload

    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="sysCode"


    S04
    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="subSysCode"


    S0401
    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="fileType"


    image
    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="filePermission"


    PUBLIC
    ------WebKitFormBoundarymAyGmnyhpf3UBdec
    Content-Disposition: form-data; name="file"; filename="2.jpg"
    Content-Type: image/jpeg

    ------WebKitFormBoundarymAyGmnyhpf3UBdec--



#
yaml用例 - test: name: 上传文件 request: url: $url/api/add method: POST files: sysCode: [null,'S04'] subSysCode: [null,'S0401'] fileType: [null,'image' ] filePermission: [null,'PUBLIC'] file: ['2.jpg',$file1,'image/jpeg'] extract: - fileId: content.responseBody.fileId validate: - eq: [status_code, 200] - eq: [content.status, SUCCESS] - eq: [content.status, SUCCESS] variables: - filePath: "D:\\Pictures\\2.jpg" - file1: ${get_file($filePath)}

file参数说明:
file = {'name': (<filename>, <file object>,<content type>, <per-part headers>)}

 

#debugtalk.py
# 读取文件内容
def get_file(filePath):
    return open(filePath, "rb")
posted on 2018-10-12 10:14  蜗牛也是妞  阅读(4899)  评论(13编辑  收藏  举报