How to run one request from another using Pre-request Script in Postman

后端 未结 6 1245

I\'m trying to send an authenticated request with one click in postman.

So, I have request named \"Oauth\" and I\'m using Tests to store the token in a local variable.

6条回答
  •  别那么骄傲
    2021-01-31 02:37

    I have tried multiple solutions, the below solution is related to when you are parsing the response for request 1 and passing any variable into the second request parameter. ( In this Example variable is Lastname. )

    Note:- data and user are JSON objects.``

    postman.clearGlobalVariable("variable_key");
    postman.clearEnvironmentVariable("variable_key");
    tests["Body matches string"] = responseBody.has("enter the match string ");
     var jsonData = JSON.parse(responseBody);
      var result = jsonData.data;
      var lastName = result.user.lastName;
    tests["Body matches lastName "] = responseBody.has(lastName);
    tests["print  matches lastName " + lastName ] = lastName;
    

提交回复
热议问题