httprunner3.0 upload方法不支持参数化怎么处理

2021-11-08  本文已影响0人  gz_tester

问题:在实际操作过程中发现,当在upload方法中不支持参数化,但是有些数据必须通过上个接口的extract才能获取到
解决方案:
可以调用httprunner中的m_encoder方法

config:
    name: "测试流程"
    base_url: ${ENV(BASE_URL)}
    variables:
        username: "test"
teststeps:
    -   name: "步骤1"
        request:
            method: POST
            url: /test/test
            json:
                emplNo: "1"
        setup_hooks:
            - ${headers2($request, $username)}
        validate:
            -   eq: ["status_code", 200]
            -   eq: [json.code, "200"]
            -   eq: [json.message, "ok"]
        extract:
            -   applyId: body.data.id
      
    -   name: "步骤2:上传离职附件"
        variables:
            file: "testdata/leave_apply.png"
            aid: ${to_string($applyId)}
            at: "2"
            m_encoder: ${multipart_encoder(file=$file, applyId=$aid, at=$at)}
        request:
            method: POST
            url: /test/test
            headers:
                Content-Type: "${multipart_content_type($m_encoder)}"
            data: $m_encoder
        setup_hooks:
            - ${headers_upload($request, $username)}
        validate:
            -   eq: ["status_code", 200]
            -   eq: [json.code, "200"]
            -   eq: [json.message, "ok"]
上一篇下一篇

猜你喜欢

热点阅读