当前位置:网站首页>Variable setting in postman

Variable setting in postman

2022-06-24 20:48:00 m0_ sixty-two million four hundred and ninety-six thousand nine

1. Variable ( overall situation / aggregate / Environmental Science )

Variables allow us to store and reuse their values in requests or scripts , By saving values in variables , You can assemble , Environment or request .

For us to do interface testing , Another very important function .

stay postman The three commonly used variables are global variables , environment variable , Set variable .

(1.) Global variables : Once global variables are declared , Global availability , in other words postman Any set in , This variable can be used in any request . Its scope is the largest .

(2.) environment variable : To declare environment variables , First of all, the creation environment , Then variables can be created in the environment . If you want to use environment variables , You have to choose first ( Import ) This environment , So you can use variables in this environment . It should be noted that the environment can also create multiple . There can be multiple variables in each environment .

(3.) Set variable : Set variables are set specific , That is to say, the declared variable must be based on a collection , Its scope of use is only valid for this collection .

Their scope ranges from large to small : Global variables > Set variable > environment variable . When the same variable is declared in several different scopes , The smallest variable will be used in priority to make .

To use a value in a variable, simply 2 A step , They are defining variables and getting variables .

  1. Defining variables ( Set a variable )

  2. Get variable ( Access variables )

  3. Define global variables and environment variables , Click the pinion in the upper right corner to pop up the following interface , You can define global variables or environment variables according to requirements .

  4. Global variables and environment variables that have been defined , You can do a quick look

      Define set variables
  5. Select a collection , Open to see more actions (...) menu , Then click Edit . choice “ Variable ” Tab to edit or add to collection variables         Get variable   

  6. Define variables , Then you can use variables . It should be noted that , Get variables in different places , The rules of writing are also different .

    If you get the variable in the request parameter , Whether it's getting global variables , Or environment variables , Or set variables , The way to get it is the same writing rules :{ { Variable name }}

  7. The request parameters refer to :URL,Params , Authorization , Headers , Body

  8. Get environment variables :pm.environment.get(‘ Variable name ’)

  9. Get global variables :pm.globals.get(' Variable name ')

  10. Get collection variables :pm.pm.collectionVariables.get.get(' Variable name ')

  11. If it's where the code is written (Tests,Pre-requests Script) Get variable , Get different types of variables , The code is different , As follows :

  12.   Variables are used in a wide range of scenarios , For example, we will talk about Interface Association later , Variables are used in the pre request script

原网站

版权声明
本文为[m0_ sixty-two million four hundred and ninety-six thousand nine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211325595732.html