POSTMAN经常使用语句

  1. 设置环境变量       pm.environment.set("key","value")json

  2.  获取环境变量      pm.environment.get("key")app

  3. 清除环境变量       pm.environment.unset("key")ide

  4. 发送http请求       pm.sendRequest(request,function(err,res){})url

    示例:spa

        

        var data = {字符串

            "file": {get

                "title""sahjf",string

                "fileB64": res.data.file.fileB64,it

                "fileType": fileType,io

                "fileDesc""签章"

            }

        }

        


        const echoPostRequest = {

            url:'http://127.0.0.1:13001/mssg2/enterprise/fileVerify',

            method:'POST',

            header:'Content-Type:application/json',

            body:{

                mode:'raw',

                raw :JSON.stringify(data)

            }

        }

        

        pm.sendRequest(echoPostRequest,function(err,res){

            pm.test("Body matches string"function () {

                pm.expect(res.text()).to.include("成功");

            });

        })

5. 断言:返回结果中包含某个字符串

   pm.test(“Body matches string”, function () {
        pm.expect(pm.response.text()).to.include(“string_you_want_to_search”);
    });

6.转换返回结果,并获取某个字段内容

    返回结果:      

        {

            "status": 200,

            "message": "成功",

            "data": {

                "file": {

                    "fileB64": "xxx"

                }

            }

    }


   获取返回结果中fileB64的值:     

        var res = pm.response.json()

         res.data.file.fileB64       ---这个为要获取的值     

相关文章
相关标签/搜索