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")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM