前言:
httprunner 底层request还是依赖于request 库;所以你如果清楚文件上传使用代码实现逻辑,理解起来就很简单
这里还是再重复解释一次它的实现原理再来解释在httprunner 的使用方式:
感兴趣去我这篇源码解读博客去看:https://www.cnblogs.com/SunshineKimi/p/13953580.html
请求参数前端:
httprunner 上传文件:
- config: name: xxxx base_url: "https://xxxxxx" - test: name: export waybill request: method: POST url: /api/test/upload headers: cookie: ${ENV(cookie)} data: menuName: 第三方仓库发货单 files: waybills: ['导入test.xlsx', '${get_export_files_jd()}'] validate: - eq: [status_code, 200] - eq: [content.success,true]
debugtalk.py:
def get_export_files_jd(): with open('./files/导入发货单-jd.xlsx','rb')as f : files = f.read() return files
test.env:
cookie=xxxxxxxxxxxxxxxxxxxxxxxxxxx
执行:
hrun testcases est_waybill_upload.yml --dot-env-path=test.env