当前位置:网站首页>Dynamic parameter association using postman

Dynamic parameter association using postman

2022-06-26 20:45:00 Gao Sheng Han

In interface testing, we often encounter the response information of the previous request as the input parameter of the next request , This is it. Dynamic parameter association ,postman How does this tool achieve dynamic parameter correlation ?

First , Add environment

secondly , Assign the data to be dynamically correlated to an environment variable

Last , Reference this variable in the latter request

1、 Add environment information

 

   choice Environments, Click on + Button to add a set of environments . Or click New Button , choice Environments To add a set of environments . According to the needs of actual test , Check the environment , Make it your current work environment .

2、 Assign the data to be dynamically correlated to an environment variable

   In the previous request Tests Tab , The data that needs to be passed to the next request , Assign to an environment variable . See attached figure .

var jsonData = JSON.parse(responseBody);  # Response to be returned responseBody Assign a value to a variable jsonData
pm.environment.set("ids0", jsonData.data.schedules[0].id);  # According to the data structure of the return response , Below it data Attribute schedules Of the first element of the list id Assign a value to a variable ids0
pm.environment.set("ids1", jsonData.data.schedules[1].id);
 
   After running this request , stay postman You can see this in the eye icon on the upper right 2 Environment variables and their values . It can also be in Tests Add the following code to the tab to print it to the console .
console.log(ids0)

3、 Reference this variable in the latter request

  

   In the latter request , Can pass {{ids0}} The environment variable is referenced in the form of double curly braces .

After executing these two requests separately , The expected effect can be achieved .postman It also provides a method of batch execution , The following will be introduced one by one

 

原网站

版权声明
本文为[Gao Sheng Han]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202161731265958.html