Postman use of global / environmental / set of variables and priority

Variable usage scenarios
Postman main variables and parameters for association

  • Application 1 : Common variable set or may be provided by use of global variables
  • Application 2 : When a set of interfaces to be tested in different environments, can create two environments, such as testthe environment and stagethe environment, both environments add base_urlvariables and set different values, url request interface is used {{base_url}}, so that only the Postman switching environment different environments can be tested
    Switching environment
  • Application 3 : Interface dependence, because the request Postman is read-only, we can not modify the request to set a good Pre-request Script script, then I generally required by the script variable to a collection / global / environmental variables, is then used in the request {{变量名}}to read variables to
    Parameterized by script to set the environment variable

Variable setting
Postman There are three variables:

  1. Collection variables (the collection and subfolders all requests entered into force) can be added in New / Edit Collection-> Variables in
    Set variable settings

  2. Global variables (effective for all requests), environmental management - Add> Globals in
    Click the gear icon to enter the environmental management page
    Environmental Management page, click Globals
    Global variables are set

  3. Environment variables (to take effect when selecting the environment), click Add to add Environmental Management page or click on the name of an existing environment variable settings into the environment
    Environment variable settings

  • VARIAVLE: variable name
  • INITIAL VALUE: The initial share value, the default value for the team when others shared use
  • CURRENT VALUE: current value, variable value of their current use (generally we can only set this value)
  • Perisit All: Keep all, the current value (CURRENT VALUE) for their own use to replace all of the initial value
  • Reset All: Reset all, all of the current CURRENT VALUE reset to the initial value as the current

Use variables

  1. Request url, params body parameters or table or JSON / XML text by {{变量名}}using
    Using the URL or the parameter tables
    Use in the Body
  2. Use in Pre-request Script and Tests script
    in the script required by using the following statement
var v_a = pm.variables.get("a"); // 获取项目变量
var g_a = pm.globals.get("a");  // 获取全局变量
var e_a = pm.environment.get("a");  // 获取环境变量

pm.variables.set("a", "c3"); //设置集合变量
pm.globals.set("a", "g3");  // 设置全局变量
pm.environment.set("a", "e3");  //设置环境变量

Note To select the corresponding environment when using environment variables

Variable priority
when variable the same name, priority:
the environment variable> Collection variable> global variable (Globals)

For more information, please add add learning of micro letter: lockingfree get

Guess you like

Origin www.cnblogs.com/superhin/p/10984016.html