httprunner2.x--上传图片:upload 方式-推荐使用

在 HttpRunner 中,集成了requests_toolbelt 的文件上传功能,可以通过 upload 关键字简化文件的上传。

源码如下:httprunner-2.4.3\httprunner\ext\uploader\__init__.py

""" upload test extension.
If you want to use this extension, you should install the following dependencies first.
- requests_toolbelt
- filetype
Then you can write upload test script as below:
    - test:
        name: upload file
        request:
            url: http://httpbin.org/upload
            method: POST
            headers:
                Cookie: session=AAA-BBB-CCC
            upload:
                file: "data/file_to_upload"
                field1: "value1"
                field2: "value2"
        validate:
            - eq: ["status_code", 200]

  

使用格式:

upload:
        <name属性>: <文件路径及名称>

 

api文件

name: upload关键字

request:
    url: http://graph.baidu.com/upload
    method: POST
    #上传图片
    upload:
        # name属性:文件路径及名称
        image: 'data\kenan.jpg'
validate:
    - eq: ["status_code", 200]

  

测试用例

config:
    name: 百度上传文件-upload关键字

teststeps:
-
    name:  step 1
    api: api/upload1.yml
    validate:
        - eq: ["status_code", 200]
        - eq: [content.msg, Success]

 

测试报告

 

 

  

  

 

posted @ 2021-06-04 11:00  莫使娇躯空对月  阅读(188)  评论(0编辑  收藏  举报