美文网首页
httprunner3.0 upload方法不支持参数化怎么处理

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

作者: gz_tester | 来源:发表于2021-11-08 17:21 被阅读0次

    问题:在实际操作过程中发现,当在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"]
    

    相关文章

      网友评论

          本文标题:httprunner3.0 upload方法不支持参数化怎么处理

          本文链接:https://www.haomeiwen.com/subject/vmruzltx.html